Add "*" for the current context

This commit is contained in:
Djordje Lukic 2020-05-18 15:16:05 +02:00
parent cf1be96833
commit 0bd18986dd
2 changed files with 8 additions and 2 deletions

View File

@ -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()

View File

@ -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"))