@@ -24,57 +24,52 @@ import (
2424 "github.com/warrant-dev/warrant-cli/internal/reader"
2525)
2626
27+ var listEnvs bool
28+
2729func init () {
28- envCmd .AddCommand (listEnvCmd )
30+ envCmd .Flags ().BoolVarP (& listEnvs , "list" , "l" , false , "list all configured environments" )
31+
2932 envCmd .AddCommand (addEnvCmd )
3033 envCmd .AddCommand (removeEnvCmd )
3134 envCmd .AddCommand (switchEnvCmd )
35+
3236 rootCmd .AddCommand (envCmd )
3337}
3438
3539var envCmd = & cobra.Command {
3640 Use : "env" ,
37- Short : "Get the name of the current active environment" ,
38- Long : "Get the name of the current active environment." ,
41+ Short : "List configured environment(s) " ,
42+ Long : "List configured environment(s), including the current active environment." ,
3943 Example : `
40- warrant env` ,
44+ warrant env
45+ warrant env --list` ,
4146 Args : cobra .NoArgs ,
4247 RunE : func (cmd * cobra.Command , args []string ) error {
4348 config := GetConfigOrExit ()
44- fmt .Println (config .ActiveEnvironment )
4549
46- return nil
47- },
48- }
50+ if listEnvs {
51+ if len (config .Environments ) == 1 {
52+ fmt .Println (config .ActiveEnvironment )
53+ return nil
54+ }
4955
50- var listEnvCmd = & cobra.Command {
51- Use : "list" ,
52- Short : "List all configured environments" ,
53- Long : "List all configured environments, including the current active environment denoted by a * prefix." ,
54- Example : `
55- warrant list` ,
56- Args : cobra .NoArgs ,
57- RunE : func (cmd * cobra.Command , args []string ) error {
58- config := GetConfigOrExit ()
56+ envs := make ([]string , 0 , len (config .Environments ))
57+ for k := range config .Environments {
58+ envs = append (envs , k )
59+ }
60+ sort .Strings (envs )
61+ for _ , env := range envs {
62+ if env == config .ActiveEnvironment {
63+ fmt .Println (termenv .String ("* " + env ).Bold ())
64+ } else {
65+ fmt .Println (" " + env )
66+ }
67+ }
5968
60- if len (config .Environments ) == 1 {
61- fmt .Println (config .ActiveEnvironment )
6269 return nil
6370 }
6471
65- envs := make ([]string , 0 , len (config .Environments ))
66- for k := range config .Environments {
67- envs = append (envs , k )
68- }
69- sort .Strings (envs )
70- for _ , env := range envs {
71- if env == config .ActiveEnvironment {
72- fmt .Println (termenv .String ("* " + env ).Bold ())
73- } else {
74- fmt .Println (" " + env )
75- }
76- }
77-
72+ fmt .Println (config .ActiveEnvironment )
7873 return nil
7974 },
8075}
@@ -132,8 +127,8 @@ warrant remove test`,
132127
133128var switchEnvCmd = & cobra.Command {
134129 Use : "switch <envName>" ,
135- Short : "Switch to the given environment" ,
136- Long : "Switch to the given environment, provided it exists in config." ,
130+ Short : "Switch to a given environment" ,
131+ Long : "Switch to a given environment, provided it exists in config." ,
137132 Example : `
138133warrant switch prod` ,
139134 Args : cobra .ExactArgs (1 ),
0 commit comments