Bladeren bron

Add "*" for the current context

Djordje Lukic 5 jaren geleden
bovenliggende
commit
0bd18986dd
2 gewijzigde bestanden met toevoegingen van 8 en 2 verwijderingen
  1. 7 1
      cli/cmd/context/ls.go
  2. 1 1
      tests/e2e/e2e.go

+ 7 - 1
cli/cmd/context/ls.go

@@ -35,6 +35,7 @@ import (
 
 	"github.com/spf13/cobra"
 
+	apicontext "github.com/docker/api/context"
 	"github.com/docker/api/context/store"
 )
 
@@ -52,6 +53,7 @@ func listCommand() *cobra.Command {
 }
 
 func runList(ctx context.Context) error {
+	currentContext := apicontext.CurrentContext(ctx)
 	s := store.ContextStore(ctx)
 	contexts, err := s.List()
 	if err != nil {
@@ -63,7 +65,11 @@ func runList(ctx context.Context) error {
 	format := "%s\t%s\t%s\n"
 
 	for _, c := range contexts {
-		fmt.Fprintf(w, format, c.Name, c.Metadata.Description, c.Metadata.Type)
+		contextName := c.Name
+		if c.Name == currentContext {
+			contextName += " *"
+		}
+		fmt.Fprintf(w, format, contextName, c.Metadata.Description, c.Metadata.Type)
 	}
 
 	return w.Flush()

+ 1 - 1
tests/e2e/e2e.go

@@ -59,7 +59,7 @@ func main() {
 	It("uses the test context", func() {
 		currentContext := NewDockerCommand("context", "use", "test-example").ExecOrDie()
 		Expect(currentContext).To(ContainSubstring("test-example"))
-		output := NewCommand("docker", "context", "ls").ExecOrDie()
+		output := NewDockerCommand("context", "ls").ExecOrDie()
 		Expect(output).To(ContainSubstring("test-example *"))
 		output = NewDockerCommand("context", "show").ExecOrDie()
 		Expect(output).To(ContainSubstring("test-example"))