-
Notifications
You must be signed in to change notification settings - Fork 32
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
Merged
+126
−99
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c438267
feat: load environment variables from '.env' file for hook commands
zimeg fb0cce1
Merge branch 'main' into zimeg-feat-load-hook-dotenv
zimeg 9b8c7a1
feat: list available ".env" variable names for non-hosted apps
zimeg 0266d17
Merge branch 'main' into zimeg-feat-load-hook-dotenv
zimeg 72828ec
test: make clear the purpose of env var hook tests
zimeg f63d0ff
refactor: use a slackdotenv package for reading variables from .env file
zimeg 4b29a23
docs: godoc slackdotenv
zimeg 2324d5f
Merge branch 'main' into zimeg-feat-load-hook-dotenv
zimeg 9160bcc
refactor: set command shell environment variables from hook options
zimeg 7dfc00d
test: assert expected cases of shell environment are parsed in order
zimeg c1382df
test: confirm inline comments are ignored
zimeg 525f693
feat: output warning for invalid .env file parsing
zimeg 6cadb2d
chore: claude errorcodes
zimeg b997f52
Merge branch 'zimeg-feat-load-hook-dotenv' into zimeg-feat-dotenv-list
zimeg 9938327
fix: use slackdotenv.Read in env list command
zimeg c381609
Merge branch 'main' into zimeg-feat-dotenv-list
zimeg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ import ( | |
| "github.com/slackapi/slack-cli/internal/cmdutil" | ||
| "github.com/slackapi/slack-cli/internal/prompts" | ||
| "github.com/slackapi/slack-cli/internal/shared" | ||
| "github.com/slackapi/slack-cli/internal/slackdotenv" | ||
| "github.com/slackapi/slack-cli/internal/slacktrace" | ||
| "github.com/slackapi/slack-cli/internal/style" | ||
| "github.com/spf13/cobra" | ||
|
|
@@ -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 := slackdotenv.Read(clients.Fs) | ||
| 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 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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