Skip to content

Commit 3e5d6fb

Browse files
committed
fix: format env command section headers together as titles
1 parent 24c1d2c commit 3e5d6fb

4 files changed

Lines changed: 32 additions & 46 deletions

File tree

cmd/env/add.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func runEnvAddCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, arg
126126

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

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
"Add, remove, or list environment variables for the app.",
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 environment variables available to the app at runtime.",
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 stored 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/remove.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func runEnvRemoveCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command,
107107
clients.IO.PrintTrace(ctx, slacktrace.EnvRemoveSuccess)
108108
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
109109
Emoji: "evergreen_tree",
110-
Text: "App Environment",
110+
Text: "Environment Remove",
111111
Secondary: []string{
112112
"The app has no environment variables to remove",
113113
},
@@ -143,7 +143,7 @@ func runEnvRemoveCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command,
143143
clients.IO.PrintTrace(ctx, slacktrace.EnvRemoveSuccess)
144144
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
145145
Emoji: "evergreen_tree",
146-
Text: "App Environment",
146+
Text: "Environment Remove",
147147
Secondary: []string{
148148
fmt.Sprintf(
149149
"Successfully removed \"%s\" from the app's environment variables",

0 commit comments

Comments
 (0)