-
Notifications
You must be signed in to change notification settings - Fork 33
feat: list available ".env" variable names for non-hosted apps #437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: zimeg-feat-load-hook-dotenv
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import ( | |
| "strings" | ||
|
|
||
| "github.com/slackapi/slack-cli/internal/cmdutil" | ||
| "github.com/slackapi/slack-cli/internal/hooks" | ||
| "github.com/slackapi/slack-cli/internal/prompts" | ||
| "github.com/slackapi/slack-cli/internal/shared" | ||
| "github.com/slackapi/slack-cli/internal/slacktrace" | ||
|
|
@@ -34,11 +35,13 @@ func NewEnvListCommand(clients *shared.ClientFactory) *cobra.Command { | |
| Use: "list [flags]", | ||
| Short: "List all environment variables for the app", | ||
| Long: strings.Join([]string{ | ||
| "List all of the environment variables of an app deployed to Slack managed", | ||
| "infrastructure.", | ||
| "List environment variables available to the app at runtime.", | ||
| "", | ||
| "This command is supported for apps deployed to Slack managed infrastructure but", | ||
| "other apps can attempt to run the command with the --force flag.", | ||
| "Commands that run in the context of a project source environment variables from", | ||
| "the \".env\" file. This includes the \"run\" command.", | ||
| "", | ||
| "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{ | ||
| { | ||
|
|
@@ -58,17 +61,9 @@ func NewEnvListCommand(clients *shared.ClientFactory) *cobra.Command { | |
| return cmd | ||
| } | ||
|
|
||
| // preRunEnvListCommandFunc determines if the command is supported for a project | ||
| // and configures flags | ||
| func preRunEnvListCommandFunc(ctx context.Context, clients *shared.ClientFactory) error { | ||
| err := cmdutil.IsValidProjectDirectory(clients) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if clients.Config.ForceFlag { | ||
| return nil | ||
| } | ||
| return cmdutil.IsSlackHostedProject(ctx, clients) | ||
| // preRunEnvListCommandFunc determines if the command is run in a valid project | ||
| func preRunEnvListCommandFunc(_ context.Context, clients *shared.ClientFactory) error { | ||
| return cmdutil.IsValidProjectDirectory(clients) | ||
| } | ||
|
|
||
| // runEnvListCommandFunc outputs environment variables for a selected app | ||
|
|
@@ -81,20 +76,34 @@ func runEnvListCommandFunc( | |
| selection, err := appSelectPromptFunc( | ||
| ctx, | ||
| clients, | ||
| prompts.ShowHostedOnly, | ||
| prompts.ShowAllEnvironments, | ||
| prompts.ShowInstalledAppsOnly, | ||
| ) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| variableNames, err := clients.API().ListVariables( | ||
| ctx, | ||
| selection.Auth.Token, | ||
| selection.App.AppID, | ||
| ) | ||
| if err != nil { | ||
| return err | ||
| // Gather environment variables for either a ROSI app from the Slack API method | ||
| // or read from project files. | ||
| var variableNames []string | ||
| if !selection.App.IsDev && cmdutil.IsSlackHostedProject(ctx, clients) == nil { | ||
| variableNames, err = clients.API().ListVariables( | ||
| ctx, | ||
| selection.Auth.Token, | ||
| selection.App.AppID, | ||
| ) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } else { | ||
| dotEnv, err := hooks.LoadDotEnv(clients.Fs) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🪝 note: We reuse the logic that 🐟 ramble: We don't require app selection before this at this point, but we might consider keeping it to avoid breaking change if it becomes required later. FWIW it's required for hosted apps so this is familiar experience I think! |
||
| if err != nil { | ||
| return err | ||
| } | ||
| variableNames = make([]string, 0, len(dotEnv)) | ||
| for k := range dotEnv { | ||
| variableNames = append(variableNames, k) | ||
| } | ||
| } | ||
|
|
||
| count := len(variableNames) | ||
|
|
@@ -112,22 +121,23 @@ func runEnvListCommandFunc( | |
| }, | ||
| })) | ||
|
|
||
| if len(variableNames) <= 0 { | ||
| if count <= 0 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice catch i wonder why count was not used here before 🤔 |
||
| return nil | ||
| } | ||
|
|
||
| sort.Strings(variableNames) | ||
| variableLabel := []string{} | ||
| variableLabels := make([]string, 0, count) | ||
| for _, v := range variableNames { | ||
| variableLabel = append( | ||
| variableLabel, | ||
| variableLabels = append( | ||
| variableLabels, | ||
| fmt.Sprintf("%s: %s", v, style.Secondary("***")), | ||
| ) | ||
| } | ||
| clients.IO.PrintTrace(ctx, slacktrace.EnvListVariables, variableNames...) | ||
| clients.IO.PrintInfo(ctx, false, "%s", style.Sectionf(style.TextSection{ | ||
| Emoji: "evergreen_tree", | ||
| Text: "App Environment", | ||
| Secondary: variableLabel, | ||
| Secondary: variableLabels, | ||
| })) | ||
|
|
||
| return nil | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📸 Preview