Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func NewCommand(clients *shared.ClientFactory) *cobra.Command {
"Set, unset, or list environment variables for the project.",
"",
"Commands that run in the context of a project source environment variables from",
"the \".env\" file. This includes the \"run\" command.",
`the ".env" file. This includes the "run" command.`,
"",
"The \"deploy\" command gathers environment variables from the \".env\" file as well",
`The "deploy" command gathers environment variables from the ".env" file as well`,
"unless the app is using ROSI features.",
"",
`Explore more: {{LinkText "https://docs.slack.dev/tools/slack-cli/guides/using-environment-variables-with-the-slack-cli"}}`,
Expand Down
46 changes: 19 additions & 27 deletions cmd/env/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ func NewEnvListCommand(clients *shared.ClientFactory) *cobra.Command {
"List the environment variables available to the project.",
"",
"Commands that run in the context of a project source environment variables from",
"the \".env\" file. This includes the \"run\" command.",
`the ".env" file. This includes the "run" command.`,
"",
"The \"deploy\" command gathers environment variables from the \".env\" file as well",
`The "deploy" command gathers environment variables from the ".env" file as well`,
"unless the app is using ROSI features.",
}, "\n"),
Example: style.ExampleCommandsf([]style.ExampleCommand{
Expand Down Expand Up @@ -115,36 +115,28 @@ func runEnvListCommandFunc(

count := len(variableNames)
clients.IO.PrintTrace(ctx, slacktrace.EnvListCount, strconv.Itoa(count))
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
Emoji: "evergreen_tree",
Text: "App Environment",
Secondary: []string{
fmt.Sprintf(
"There %s %d %s stored in this environment",
style.Pluralize("is", "are", count),
count,
style.Pluralize("variable", "variables", count),
),
},
}))

if count <= 0 {
return nil
details := []string{
fmt.Sprintf(
"There %s %d %s set in this environment",
style.Pluralize("is", "are", count),
count,
style.Pluralize("variable", "variables", count),
),
}

sort.Strings(variableNames)
variableLabels := make([]string, 0, count)
for _, v := range variableNames {
variableLabels = append(
variableLabels,
fmt.Sprintf("%s: %s", v, style.Secondary("***")),
)
if count > 0 {
sort.Strings(variableNames)
for _, v := range variableNames {
details = append(details, fmt.Sprintf("- %s: %s", v, style.Secondary("***")))
}
clients.IO.PrintTrace(ctx, slacktrace.EnvListVariables, variableNames...)
}
clients.IO.PrintTrace(ctx, slacktrace.EnvListVariables, variableNames...)
clients.IO.PrintInfo(ctx, false, "%s", style.Sectionf(style.TextSection{

clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
Emoji: "evergreen_tree",
Text: "App Environment",
Secondary: variableLabels,
Text: "Environment List",
Secondary: details,
}))

return nil
Expand Down
26 changes: 10 additions & 16 deletions cmd/env/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func runEnvSetCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, arg

// Add the environment variable using either the Slack API method or the
// project ".env" file depending on the app hosting.
var details []string
if hosted && !selection.App.IsDev {
err := clients.API().AddVariable(
ctx,
Expand All @@ -138,14 +139,7 @@ func runEnvSetCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, arg
if err != nil {
return err
}
clients.IO.PrintTrace(ctx, slacktrace.EnvSetSuccess)
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
Emoji: "evergreen_tree",
Text: "App Environment",
Secondary: []string{
fmt.Sprintf("Successfully added \"%s\" as an app environment variable", variableName),
},
}))
details = append(details, fmt.Sprintf("Successfully set \"%s\" as an app environment variable", variableName))
} else {
exists, err := afero.Exists(clients.Fs, ".env")
if err != nil {
Expand All @@ -155,17 +149,17 @@ func runEnvSetCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, arg
if err != nil {
return err
}
clients.IO.PrintTrace(ctx, slacktrace.EnvSetSuccess)
var details []string
if !exists {
details = append(details, "Created a project .env file that shouldn't be added to version control")
}
details = append(details, fmt.Sprintf("Successfully added \"%s\" as a project environment variable", variableName))
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
Emoji: "evergreen_tree",
Text: "App Environment",
Secondary: details,
}))
details = append(details, fmt.Sprintf("Successfully set \"%s\" as a project environment variable", variableName))
}

clients.IO.PrintTrace(ctx, slacktrace.EnvSetSuccess)
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
Emoji: "evergreen_tree",
Text: "Environment Set",
Secondary: details,
}))
return nil
}
16 changes: 8 additions & 8 deletions cmd/env/unset.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func runEnvUnsetCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, a
clients.IO.PrintTrace(ctx, slacktrace.EnvUnsetSuccess)
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
Emoji: "evergreen_tree",
Text: "App Environment",
Text: "Environment Unset",
Secondary: []string{
"The app has no environment variables to remove",
},
Expand All @@ -119,7 +119,7 @@ func runEnvUnsetCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, a
}
selected, err := clients.IO.SelectPrompt(
ctx,
"Select a variable to remove",
"Select a variable to unset",
variables,
iostreams.SelectPromptConfig{
Flag: clients.Config.Flags.Lookup("name"),
Expand All @@ -139,7 +139,7 @@ func runEnvUnsetCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, a
clients.IO.PrintTrace(ctx, slacktrace.EnvUnsetSuccess)
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
Emoji: "evergreen_tree",
Text: "App Environment",
Text: "Environment Unset",
Secondary: []string{
"The project has no environment variables to remove",
},
Expand All @@ -153,7 +153,7 @@ func runEnvUnsetCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, a
sort.Strings(variables)
selected, err := clients.IO.SelectPrompt(
ctx,
"Select a variable to remove",
"Select a variable to unset",
variables,
iostreams.SelectPromptConfig{
Flag: clients.Config.Flags.Lookup("name"),
Expand Down Expand Up @@ -181,9 +181,9 @@ func runEnvUnsetCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, a
clients.IO.PrintTrace(ctx, slacktrace.EnvUnsetSuccess)
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
Emoji: "evergreen_tree",
Text: "App Environment",
Text: "Environment Unset",
Secondary: []string{
fmt.Sprintf("Successfully removed \"%s\" as an app environment variable", variableName),
fmt.Sprintf("Successfully unset \"%s\" as an app environment variable", variableName),
},
}))
} else {
Expand All @@ -194,9 +194,9 @@ func runEnvUnsetCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, a
clients.IO.PrintTrace(ctx, slacktrace.EnvUnsetSuccess)
clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{
Emoji: "evergreen_tree",
Text: "App Environment",
Text: "Environment Unset",
Secondary: []string{
fmt.Sprintf("Successfully removed \"%s\" as a project environment variable", variableName),
fmt.Sprintf("Successfully unset \"%s\" as a project environment variable", variableName),
},
}))
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/env/unset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func Test_Env_RemoveCommand(t *testing.T) {
cm.IO.On(
"SelectPrompt",
mock.Anything,
"Select a variable to remove",
"Select a variable to unset",
mock.Anything,
iostreams.MatchPromptConfig(iostreams.SelectPromptConfig{
Flag: cm.Config.Flags.Lookup("name"),
Expand Down Expand Up @@ -180,7 +180,7 @@ func Test_Env_RemoveCommand(t *testing.T) {
assert.Equal(t, "OTHER=keep\n", string(content))
},
ExpectedStdoutOutputs: []string{
"Successfully removed \"SECRET\" as a project environment variable",
"Successfully unset \"SECRET\" as a project environment variable",
},
},
"remove a variable from the .env file using prompt": {
Expand All @@ -198,7 +198,7 @@ func Test_Env_RemoveCommand(t *testing.T) {
cm.IO.On(
"SelectPrompt",
mock.Anything,
"Select a variable to remove",
"Select a variable to unset",
mock.Anything,
iostreams.MatchPromptConfig(iostreams.SelectPromptConfig{
Flag: cm.Config.Flags.Lookup("name"),
Expand Down
Loading