From 6c748922b479ef1d4bf12e696ac04f1b104dd7fa Mon Sep 17 00:00:00 2001 From: Roxie Gibson Date: Sat, 17 Jul 2021 09:29:25 +0100 Subject: [PATCH] feat: added context flag to make dev easier needed until we have proper server subcommand system --- cli/cli.go | 1 + cli/common.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/cli/cli.go b/cli/cli.go index 4f3741b1..c19ec03d 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -39,6 +39,7 @@ func RunApp(version, commit string) { BranchFlag, NoPromptFlag, DebugFlag, + ContextFlag, }, } diff --git a/cli/common.go b/cli/common.go index ee019b15..b52776e0 100644 --- a/cli/common.go +++ b/cli/common.go @@ -1,6 +1,9 @@ package cli import ( + "os" + + "github.com/olekukonko/tablewriter" "github.com/urfave/cli/v2" ) @@ -176,3 +179,31 @@ var TypeFlag = &cli.StringFlag{ Value: "", Destination: &Type, } + +var Context string +var ContextFlag = &cli.StringFlag{ + Name: "context", + Value: "", + Aliases: []string{"c"}, + Destination: &Context, +} + +func createTable(columns []string) *tablewriter.Table { + table := tablewriter.NewWriter(os.Stdout) + table.SetHeader(columns) + + // Settings to create very bare tab padded table + table.SetAutoWrapText(false) + table.SetAutoFormatHeaders(true) + table.SetHeaderAlignment(tablewriter.ALIGN_LEFT) + table.SetAlignment(tablewriter.ALIGN_LEFT) + table.SetCenterSeparator("") + table.SetColumnSeparator("") + table.SetRowSeparator("") + table.SetHeaderLine(false) + table.SetBorder(false) + table.SetTablePadding("\t") // pad with tabs + table.SetNoWhiteSpace(true) + table.SetColWidth(1) + return table +}