diff --git a/cli/flags.go b/cli/flags.go index 37ba480..bb9d200 100644 --- a/cli/flags.go +++ b/cli/flags.go @@ -1,6 +1,10 @@ package cli -import "github.com/urfave/cli" +import ( + "fmt" + + "github.com/urfave/cli" +) const ( // PathEnvKey ... @@ -69,6 +73,8 @@ const ( OutputFormatRaw = "raw" // OutputFormatJSON ... OutputFormatJSON = "json" + // OutputFormatExport + OutputFormatEnvList = "envlist" ) var ( @@ -123,7 +129,7 @@ var ( } flFormat = cli.StringFlag{ Name: FormatKey, - Usage: "Output format (options: raw, json).", + Usage: fmt.Sprintf("Output format (options: %s, %s, %s).", OutputFormatRaw, OutputFormatJSON, OutputFormatEnvList), } flExpand = cli.BoolFlag{ Name: ExpandKey, diff --git a/cli/print.go b/cli/print.go index e6ab904..99b35c9 100644 --- a/cli/print.go +++ b/cli/print.go @@ -15,7 +15,7 @@ func printCmd(c *cli.Context) error { format := c.String(FormatKey) if format == "" { format = OutputFormatRaw - } else if !(format == OutputFormatRaw || format == OutputFormatJSON) { + } else if !(format == OutputFormatRaw || format == OutputFormatJSON || format == OutputFormatEnvList) { log.Fatalf("Invalid format: %s", format) } @@ -32,6 +32,8 @@ func printCmd(c *cli.Context) error { switch format { case OutputFormatRaw: printRawEnvs(envSet) + case OutputFormatEnvList: + printEnvsList(envSet) case OutputFormatJSON: if err := printJSONEnvs(envSet); err != nil { log.Fatalf("Failed to print env list, err: %s", err) @@ -116,3 +118,11 @@ func printRawEnvs(envList models.EnvsJSONListModel) { } fmt.Println() } + +func printEnvsList(envList models.EnvsJSONListModel) { + fmt.Println() + for key, value := range envList { + fmt.Printf("export %s=%q\n", key, value) + } + fmt.Println() +}