Skip to content

Commit 443ed02

Browse files
authored
Display environment list output in json (#1444)
1 parent e01a9be commit 443ed02

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

cli/cmd/env.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ package cmd
1818

1919
import (
2020
"fmt"
21+
"strings"
2122

2223
"github.com/cortexlabs/cortex/cli/types/cliconfig"
24+
"github.com/cortexlabs/cortex/cli/types/flags"
2325
"github.com/cortexlabs/cortex/pkg/lib/exit"
26+
libjson "github.com/cortexlabs/cortex/pkg/lib/json"
2427
"github.com/cortexlabs/cortex/pkg/lib/print"
2528
"github.com/cortexlabs/cortex/pkg/lib/telemetry"
2629
"github.com/cortexlabs/cortex/pkg/types"
@@ -45,6 +48,7 @@ func envInit() {
4548
_envCmd.AddCommand(_envConfigureCmd)
4649

4750
_envListCmd.Flags().SortFlags = false
51+
_envListCmd.Flags().VarP(&_flagOutput, "output", "o", fmt.Sprintf("output format: one of %s", strings.Join(flags.OutputTypeStrings(), "|")))
4852
_envCmd.AddCommand(_envListCmd)
4953

5054
_envDefaultCmd.Flags().SortFlags = false
@@ -125,6 +129,15 @@ var _envListCmd = &cobra.Command{
125129
exit.Error(err)
126130
}
127131

132+
if _flagOutput == flags.JSONOutputType {
133+
bytes, err := libjson.Marshal(cliConfig.Environments)
134+
if err != nil {
135+
exit.Error(err)
136+
}
137+
fmt.Println(string(bytes))
138+
return
139+
}
140+
128141
defaultEnv := getDefaultEnv(_generalCommandType)
129142

130143
for i, env := range cliConfig.Environments {

docs/miscellaneous/cli.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,14 @@ Usage:
148148
cortex cluster configure [flags]
149149
150150
Flags:
151-
-c, --config string path to a cluster configuration file
152-
--aws-key string aws access key id
153-
--aws-secret string aws secret access key
154-
-e, --env string environment to update (default "aws")
155-
-y, --yes skip prompts
156-
-h, --help help for configure
151+
-c, --config string path to a cluster configuration file
152+
--aws-key string aws access key id
153+
--aws-secret string aws secret access key
154+
--cluster-aws-key string aws access key id to be used by the cluster
155+
--cluster-aws-secret string aws secret access key to be used by the cluster
156+
-e, --env string environment to update (default "aws")
157+
-y, --yes skip prompts
158+
-h, --help help for configure
157159
```
158160

159161
### cluster export
@@ -213,7 +215,8 @@ Usage:
213215
cortex env list [flags]
214216
215217
Flags:
216-
-h, --help help for list
218+
-o, --output string output format: one of pretty|json (default "pretty")
219+
-h, --help help for list
217220
```
218221

219222
### env default

0 commit comments

Comments
 (0)