From 5780af6bdabbc97a02637fa47121e6262c8dd4d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20K=C3=A4mmerling?= <4281581+LKaemmerling@users.noreply.github.com> Date: Wed, 6 Feb 2019 12:00:12 +0100 Subject: [PATCH] Mark active context in context list --- CHANGES.md | 1 + cli/context_list.go | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a57072b4..79d7e7b7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/cli/context_list.go b/cli/context_list.go index 88119404..3242fa53 100644 --- a/cli/context_list.go +++ b/cli/context_list.go @@ -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") } @@ -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"] } @@ -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