Skip to content

Commit a0b5565

Browse files
zimegsrtaalejmwbrooks
authored
fix: format env command section headers together as titles (#461)
Co-authored-by: Ale Mercado <maria.mercado@slack-corp.com> Co-authored-by: Michael Brooks <mbrooks@slack-corp.com>
1 parent 0fd8736 commit a0b5565

File tree

5 files changed

+42
-56
lines changed

5 files changed

+42
-56
lines changed

cmd/env/env.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ func NewCommand(clients *shared.ClientFactory) *cobra.Command {
4040
"Set, unset, or list environment variables for the project.",
4141
"",
4242
"Commands that run in the context of a project source environment variables from",
43-
"the \".env\" file. This includes the \"run\" command.",
43+
`the ".env" file. This includes the "run" command.`,
4444
"",
45-
"The \"deploy\" command gathers environment variables from the \".env\" file as well",
45+
`The "deploy" command gathers environment variables from the ".env" file as well`,
4646
"unless the app is using ROSI features.",
4747
"",
4848
`Explore more: {{LinkText "https://docs.slack.dev/tools/slack-cli/guides/using-environment-variables-with-the-slack-cli"}}`,

cmd/env/list.go

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ func NewEnvListCommand(clients *shared.ClientFactory) *cobra.Command {
3838
"List the environment variables available to the project.",
3939
"",
4040
"Commands that run in the context of a project source environment variables from",
41-
"the \".env\" file. This includes the \"run\" command.",
41+
`the ".env" file. This includes the "run" command.`,
4242
"",
43-
"The \"deploy\" command gathers environment variables from the \".env\" file as well",
43+
`The "deploy" command gathers environment variables from the ".env" file as well`,
4444
"unless the app is using ROSI features.",
4545
}, "\n"),
4646
Example: style.ExampleCommandsf([]style.ExampleCommand{
@@ -115,36 +115,28 @@ func runEnvListCommandFunc(
115115

116116
count := len(variableNames)
117117
clients.IO.PrintTrace(ctx, slacktrace.EnvListCount, strconv.Itoa(count))
118-
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
119-
Emoji: "evergreen_tree",
120-
Text: "App Environment",
121-
Secondary: []string{
122-
fmt.Sprintf(
123-
"There %s %d %s stored in this environment",
124-
style.Pluralize("is", "are", count),
125-
count,
126-
style.Pluralize("variable", "variables", count),
127-
),
128-
},
129-
}))
130118

131-
if count <= 0 {
132-
return nil
119+
details := []string{
120+
fmt.Sprintf(
121+
"There %s %d %s set in this environment",
122+
style.Pluralize("is", "are", count),
123+
count,
124+
style.Pluralize("variable", "variables", count),
125+
),
133126
}
134127

135-
sort.Strings(variableNames)
136-
variableLabels := make([]string, 0, count)
137-
for _, v := range variableNames {
138-
variableLabels = append(
139-
variableLabels,
140-
fmt.Sprintf("%s: %s", v, style.Secondary("***")),
141-
)
128+
if count > 0 {
129+
sort.Strings(variableNames)
130+
for _, v := range variableNames {
131+
details = append(details, fmt.Sprintf("- %s: %s", v, style.Secondary("***")))
132+
}
133+
clients.IO.PrintTrace(ctx, slacktrace.EnvListVariables, variableNames...)
142134
}
143-
clients.IO.PrintTrace(ctx, slacktrace.EnvListVariables, variableNames...)
144-
clients.IO.PrintInfo(ctx, false, "%s", style.Sectionf(style.TextSection{
135+
136+
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
145137
Emoji: "evergreen_tree",
146-
Text: "App Environment",
147-
Secondary: variableLabels,
138+
Text: "Environment List",
139+
Secondary: details,
148140
}))
149141

150142
return nil

cmd/env/set.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ func runEnvSetCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, arg
127127

128128
// Add the environment variable using either the Slack API method or the
129129
// project ".env" file depending on the app hosting.
130+
var details []string
130131
if hosted && !selection.App.IsDev {
131132
err := clients.API().AddVariable(
132133
ctx,
@@ -138,14 +139,7 @@ func runEnvSetCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, arg
138139
if err != nil {
139140
return err
140141
}
141-
clients.IO.PrintTrace(ctx, slacktrace.EnvSetSuccess)
142-
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
143-
Emoji: "evergreen_tree",
144-
Text: "App Environment",
145-
Secondary: []string{
146-
fmt.Sprintf("Successfully added \"%s\" as an app environment variable", variableName),
147-
},
148-
}))
142+
details = append(details, fmt.Sprintf("Successfully set \"%s\" as an app environment variable", variableName))
149143
} else {
150144
exists, err := afero.Exists(clients.Fs, ".env")
151145
if err != nil {
@@ -155,17 +149,17 @@ func runEnvSetCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, arg
155149
if err != nil {
156150
return err
157151
}
158-
clients.IO.PrintTrace(ctx, slacktrace.EnvSetSuccess)
159-
var details []string
160152
if !exists {
161153
details = append(details, "Created a project .env file that shouldn't be added to version control")
162154
}
163-
details = append(details, fmt.Sprintf("Successfully added \"%s\" as a project environment variable", variableName))
164-
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
165-
Emoji: "evergreen_tree",
166-
Text: "App Environment",
167-
Secondary: details,
168-
}))
155+
details = append(details, fmt.Sprintf("Successfully set \"%s\" as a project environment variable", variableName))
169156
}
157+
158+
clients.IO.PrintTrace(ctx, slacktrace.EnvSetSuccess)
159+
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
160+
Emoji: "evergreen_tree",
161+
Text: "Environment Set",
162+
Secondary: details,
163+
}))
170164
return nil
171165
}

cmd/env/unset.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func runEnvUnsetCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, a
110110
clients.IO.PrintTrace(ctx, slacktrace.EnvUnsetSuccess)
111111
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
112112
Emoji: "evergreen_tree",
113-
Text: "App Environment",
113+
Text: "Environment Unset",
114114
Secondary: []string{
115115
"The app has no environment variables to remove",
116116
},
@@ -119,7 +119,7 @@ func runEnvUnsetCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, a
119119
}
120120
selected, err := clients.IO.SelectPrompt(
121121
ctx,
122-
"Select a variable to remove",
122+
"Select a variable to unset",
123123
variables,
124124
iostreams.SelectPromptConfig{
125125
Flag: clients.Config.Flags.Lookup("name"),
@@ -139,7 +139,7 @@ func runEnvUnsetCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, a
139139
clients.IO.PrintTrace(ctx, slacktrace.EnvUnsetSuccess)
140140
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
141141
Emoji: "evergreen_tree",
142-
Text: "App Environment",
142+
Text: "Environment Unset",
143143
Secondary: []string{
144144
"The project has no environment variables to remove",
145145
},
@@ -153,7 +153,7 @@ func runEnvUnsetCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, a
153153
sort.Strings(variables)
154154
selected, err := clients.IO.SelectPrompt(
155155
ctx,
156-
"Select a variable to remove",
156+
"Select a variable to unset",
157157
variables,
158158
iostreams.SelectPromptConfig{
159159
Flag: clients.Config.Flags.Lookup("name"),
@@ -181,9 +181,9 @@ func runEnvUnsetCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, a
181181
clients.IO.PrintTrace(ctx, slacktrace.EnvUnsetSuccess)
182182
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
183183
Emoji: "evergreen_tree",
184-
Text: "App Environment",
184+
Text: "Environment Unset",
185185
Secondary: []string{
186-
fmt.Sprintf("Successfully removed \"%s\" as an app environment variable", variableName),
186+
fmt.Sprintf("Successfully unset \"%s\" as an app environment variable", variableName),
187187
},
188188
}))
189189
} else {
@@ -194,9 +194,9 @@ func runEnvUnsetCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, a
194194
clients.IO.PrintTrace(ctx, slacktrace.EnvUnsetSuccess)
195195
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
196196
Emoji: "evergreen_tree",
197-
Text: "App Environment",
197+
Text: "Environment Unset",
198198
Secondary: []string{
199-
fmt.Sprintf("Successfully removed \"%s\" as a project environment variable", variableName),
199+
fmt.Sprintf("Successfully unset \"%s\" as a project environment variable", variableName),
200200
},
201201
}))
202202
}

cmd/env/unset_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func Test_Env_RemoveCommand(t *testing.T) {
127127
cm.IO.On(
128128
"SelectPrompt",
129129
mock.Anything,
130-
"Select a variable to remove",
130+
"Select a variable to unset",
131131
mock.Anything,
132132
iostreams.MatchPromptConfig(iostreams.SelectPromptConfig{
133133
Flag: cm.Config.Flags.Lookup("name"),
@@ -180,7 +180,7 @@ func Test_Env_RemoveCommand(t *testing.T) {
180180
assert.Equal(t, "OTHER=keep\n", string(content))
181181
},
182182
ExpectedStdoutOutputs: []string{
183-
"Successfully removed \"SECRET\" as a project environment variable",
183+
"Successfully unset \"SECRET\" as a project environment variable",
184184
},
185185
},
186186
"remove a variable from the .env file using prompt": {
@@ -198,7 +198,7 @@ func Test_Env_RemoveCommand(t *testing.T) {
198198
cm.IO.On(
199199
"SelectPrompt",
200200
mock.Anything,
201-
"Select a variable to remove",
201+
"Select a variable to unset",
202202
mock.Anything,
203203
iostreams.MatchPromptConfig(iostreams.SelectPromptConfig{
204204
Flag: cm.Config.Flags.Lookup("name"),

0 commit comments

Comments
 (0)