Skip to content

Commit

Permalink
Fixed the cli
Browse files Browse the repository at this point in the history
  • Loading branch information
diptanu committed Oct 4, 2016
1 parent 2c115a2 commit 7a5362d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
23 changes: 16 additions & 7 deletions command/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"strings"

"github.com/hashicorp/nomad/api"
"github.com/mitchellh/cli"
)

Expand Down Expand Up @@ -68,7 +69,7 @@ func (c *KeyringCommand) Run(args []string) int {
c.Ui.Error(fmt.Sprintf("error: %s", err))
return 1
}
fmt.Printf("List %#v", r)
c.handleKeyResponse(r)
return 0
}

Expand All @@ -79,7 +80,7 @@ func (c *KeyringCommand) Run(args []string) int {
c.Ui.Error(fmt.Sprintf("error: %s", err))
return 1
}
fmt.Printf("Install %#v", r)
c.handleKeyResponse(r)
return 0
}

Expand All @@ -90,7 +91,7 @@ func (c *KeyringCommand) Run(args []string) int {
c.Ui.Error(fmt.Sprintf("error: %s", err))
return 1
}
fmt.Printf("Use %#v", r)
c.handleKeyResponse(r)
return 0
}

Expand All @@ -101,14 +102,25 @@ func (c *KeyringCommand) Run(args []string) int {
c.Ui.Error(fmt.Sprintf("error: %s", err))
return 1
}
fmt.Printf("Remove %#v", r)
c.handleKeyResponse(r)
return 0
}

// Should never make it here
return 0
}

func (c *KeyringCommand) handleKeyResponse(resp *api.KeyringResponse) {
out := make([]string, len(resp.Keys)+1)
out[0] = "Key"
i := 1
for k := range resp.Keys {
out[i] = fmt.Sprintf("%s", k)
i = i + 1
}
c.Ui.Output(formatList(out))
}

func (c *KeyringCommand) Help() string {
helpText := `
Usage: nomad keyring [options]
Expand All @@ -133,12 +145,9 @@ Options:
-remove=<key> Remove the given key from the cluster. This
operation may only be performed on keys which are
not currently the primary key.
-token="" ACL token to use during requests. Defaults to that
of the agent.
-use=<key> Change the primary encryption key, which is used to
encrypt messages. The key must already be installed
before this operation can succeed.
-rpc-addr=127.0.0.1:8400 RPC address of the Consul agent.
`
return strings.TrimSpace(helpText)
}
Expand Down
5 changes: 5 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ func Commands(metaPtr *command.Meta) map[string]cli.CommandFactory {
Meta: meta,
}, nil
},
"keyring": func() (cli.Command, error) {
return &command.KeyringCommand{
Meta: meta,
}, nil
},
"logs": func() (cli.Command, error) {
return &command.LogsCommand{
Meta: meta,
Expand Down

0 comments on commit 7a5362d

Please sign in to comment.