Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cli/cmd/context/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (

"github.com/spf13/cobra"

apicontext "github.com/docker/api/context"
"github.com/docker/api/context/store"
)

Expand All @@ -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 {
Expand All @@ -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 += " *"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@justincormack what UX would you like for this? A star before the name might be nice. Something like:

$ docker context ls
  NAME    DESCRIPTION TYPE
* example             example
  aci                 aci
  moby                moby

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, we could have colors?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or at first, should we keep the "classic" UX : star after the name ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll merge this one, we can have the conversation on slack

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, already done :)

}
fmt.Fprintf(w, format, contextName, c.Metadata.Description, c.Metadata.Type)
}

return w.Flush()
Expand Down
19 changes: 11 additions & 8 deletions context/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ const (
)

const (
contextsDir = "contexts"
metadataDir = "meta"
metaFile = "meta.json"
dockerEndpointKey = "docker"
configDir = ".docker"
contextsDir = "contexts"
metadataDir = "meta"
metaFile = "meta.json"
)

type contextStoreKey struct{}
Expand Down Expand Up @@ -103,7 +105,7 @@ func New(opts ...Opt) (Store, error) {
return nil, err
}
s := &store{
root: filepath.Join(home, ".docker"),
root: filepath.Join(home, configDir),
}
if _, err := os.Stat(s.root); os.IsNotExist(err) {
if err = os.Mkdir(s.root, 0755); err != nil {
Expand Down Expand Up @@ -190,11 +192,12 @@ func parse(payload []byte, getter func() interface{}) (interface{}, error) {

func (s *store) GetType(meta *Metadata) string {
for k := range meta.Endpoints {
if k != "docker" {
if k != dockerEndpointKey {
return k
}
}
return "docker"

return dockerEndpointKey
}

func (s *store) Create(name string, data TypedContext) error {
Expand All @@ -220,8 +223,8 @@ func (s *store) Create(name string, data TypedContext) error {
Name: name,
Metadata: data,
Endpoints: map[string]interface{}{
"docker": dummyContext{},
(data.Type): dummyContext{},
(dockerEndpointKey): dummyContext{},
(data.Type): dummyContext{},
},
}

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down