Skip to content

Commit

Permalink
Mark active context in context list
Browse files Browse the repository at this point in the history
  • Loading branch information
LKaemmerling authored and thcyron committed Feb 6, 2019
1 parent bbb4626 commit 5780af6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Add support for JSON and Go template output
* Add support for multiple user data files
* Add length validation for API token on `hcloud context create`
* Add `active` column to context list on `hcloud context list`

## v1.11.0

Expand Down
21 changes: 18 additions & 3 deletions cli/context_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import (

var contextListTableOutput *tableOutput

type ContextPresentation struct {
Name string
Token string
Active string
}

func init() {
contextListTableOutput = newTableOutput().
AddAllowedFields(ConfigContext{}).
AddAllowedFields(ContextPresentation{}).
RemoveAllowedField("token")
}

Expand All @@ -32,7 +38,7 @@ func newContextListCommand(cli *CLI) *cobra.Command {
func runContextList(cli *CLI, cmd *cobra.Command, args []string) error {
outOpts := outputFlagsForCommand(cmd)

cols := []string{"name"}
cols := []string{"active", "name"}
if outOpts.IsSet("columns") {
cols = outOpts["columns"]
}
Expand All @@ -46,7 +52,16 @@ func runContextList(cli *CLI, cmd *cobra.Command, args []string) error {
tw.WriteHeader(cols)
}
for _, context := range cli.Config.Contexts {
tw.Write(cols, context)
presentation := ContextPresentation{
Name: context.Name,
Token: context.Token,
Active: " ",
}
if cli.Config.ActiveContext.Name == context.Name {
presentation.Active = "*"
}

tw.Write(cols, presentation)
}
tw.Flush()
return nil
Expand Down

0 comments on commit 5780af6

Please sign in to comment.