-
Notifications
You must be signed in to change notification settings - Fork 32
feat: alias env set and env unset as primary commands
#460
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
Changes from all commits
a1c20f8
272dc52
7b89f50
7a888e0
83e2b2f
047c85f
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 |
|---|---|---|
|
|
@@ -30,12 +30,13 @@ import ( | |
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func NewEnvAddCommand(clients *shared.ClientFactory) *cobra.Command { | ||
| func NewEnvSetCommand(clients *shared.ClientFactory) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "add <name> [value] [flags]", | ||
|
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: While this command is changed we also prefer the square brackets with follow up in #459 since the "name" argument has a form fallback- |
||
| Short: "Add an environment variable to the project", | ||
| Use: "set [name] [value] [flags]", | ||
| Aliases: []string{"add"}, | ||
|
Member
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: Nice to see |
||
| Short: "Set an environment variable for the project", | ||
| Long: strings.Join([]string{ | ||
| "Add an environment variable to the project.", | ||
| "Set an environment variable for the project.", | ||
| "", | ||
| "If a name or value is not provided, you will be prompted to provide these.", | ||
| "", | ||
|
|
@@ -48,24 +49,24 @@ func NewEnvAddCommand(clients *shared.ClientFactory) *cobra.Command { | |
| Example: style.ExampleCommandsf([]style.ExampleCommand{ | ||
| { | ||
| Meaning: "Prompt for an environment variable", | ||
| Command: "env add", | ||
| Command: "env set", | ||
| }, | ||
| { | ||
| Meaning: "Add an environment variable", | ||
| Command: "env add MAGIC_PASSWORD abracadbra", | ||
| Meaning: "Set an environment variable", | ||
| Command: "env set MAGIC_PASSWORD abracadbra", | ||
| }, | ||
| { | ||
| Meaning: "Prompt for an environment variable value", | ||
| Command: "env add SECRET_PASSWORD", | ||
| Command: "env set SECRET_PASSWORD", | ||
| }, | ||
| }), | ||
| Args: cobra.MaximumNArgs(2), | ||
| PreRunE: func(cmd *cobra.Command, args []string) error { | ||
| ctx := cmd.Context() | ||
| return preRunEnvAddCommandFunc(ctx, clients, cmd) | ||
| return preRunEnvSetCommandFunc(ctx, clients, cmd) | ||
| }, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return runEnvAddCommandFunc(clients, cmd, args) | ||
| return runEnvSetCommandFunc(clients, cmd, args) | ||
| }, | ||
| } | ||
|
|
||
|
|
@@ -74,15 +75,15 @@ func NewEnvAddCommand(clients *shared.ClientFactory) *cobra.Command { | |
| return cmd | ||
| } | ||
|
|
||
| // preRunEnvAddCommandFunc determines if the command is run in a valid project | ||
| // preRunEnvSetCommandFunc determines if the command is run in a valid project | ||
| // and configures flags | ||
| func preRunEnvAddCommandFunc(ctx context.Context, clients *shared.ClientFactory, cmd *cobra.Command) error { | ||
| func preRunEnvSetCommandFunc(ctx context.Context, clients *shared.ClientFactory, cmd *cobra.Command) error { | ||
| clients.Config.SetFlags(cmd) | ||
| return cmdutil.IsValidProjectDirectory(clients) | ||
| } | ||
|
|
||
| // runEnvAddCommandFunc sets an app environment variable to given values | ||
| func runEnvAddCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, args []string) error { | ||
| // runEnvSetCommandFunc sets an app environment variable to given values | ||
| func runEnvSetCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, args []string) error { | ||
| ctx := cmd.Context() | ||
|
|
||
| // Hosted apps require selecting an app before gathering variable inputs. | ||
|
|
@@ -137,7 +138,7 @@ func runEnvAddCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, arg | |
| if err != nil { | ||
| return err | ||
| } | ||
| clients.IO.PrintTrace(ctx, slacktrace.EnvAddSuccess) | ||
| clients.IO.PrintTrace(ctx, slacktrace.EnvSetSuccess) | ||
| clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{ | ||
| Emoji: "evergreen_tree", | ||
| Text: "App Environment", | ||
|
|
@@ -154,7 +155,7 @@ func runEnvAddCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, arg | |
| if err != nil { | ||
| return err | ||
| } | ||
| clients.IO.PrintTrace(ctx, slacktrace.EnvAddSuccess) | ||
| 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") | ||
|
|
||
|
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. looking great!! i noticed there are still a few references to removing in the file 👁️🗨️
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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,12 +30,13 @@ import ( | |
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func NewEnvRemoveCommand(clients *shared.ClientFactory) *cobra.Command { | ||
| func NewEnvUnsetCommand(clients *shared.ClientFactory) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "remove <name> [flags]", | ||
| Short: "Remove an environment variable from the project", | ||
| Use: "unset [name] [flags]", | ||
| Aliases: []string{"remove"}, | ||
|
Member
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: Nice to see |
||
| Short: "Unset an environment variable from the project", | ||
| Long: strings.Join([]string{ | ||
| "Remove an environment variable from the project.", | ||
| "Unset an environment variable from the project.", | ||
| "", | ||
| "If no variable name is provided, you will be prompted to select one.", | ||
| "", | ||
|
|
@@ -47,21 +48,21 @@ func NewEnvRemoveCommand(clients *shared.ClientFactory) *cobra.Command { | |
| }, "\n"), | ||
| Example: style.ExampleCommandsf([]style.ExampleCommand{ | ||
| { | ||
| Meaning: "Select an environment variable to remove", | ||
| Command: "env remove", | ||
| Meaning: "Select an environment variable to unset", | ||
| Command: "env unset", | ||
| }, | ||
| { | ||
| Meaning: "Remove an environment variable", | ||
| Command: "env remove MAGIC_PASSWORD", | ||
| Meaning: "Unset an environment variable", | ||
| Command: "env unset MAGIC_PASSWORD", | ||
| }, | ||
| }), | ||
| Args: cobra.MaximumNArgs(1), | ||
| PreRunE: func(cmd *cobra.Command, args []string) error { | ||
| ctx := cmd.Context() | ||
| return preRunEnvRemoveCommandFunc(ctx, clients, cmd) | ||
| return preRunEnvUnsetCommandFunc(ctx, clients, cmd) | ||
| }, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return runEnvRemoveCommandFunc(clients, cmd, args) | ||
| return runEnvUnsetCommandFunc(clients, cmd, args) | ||
| }, | ||
| } | ||
|
|
||
|
|
@@ -70,15 +71,15 @@ func NewEnvRemoveCommand(clients *shared.ClientFactory) *cobra.Command { | |
| return cmd | ||
| } | ||
|
|
||
| // preRunEnvRemoveCommandFunc determines if the command is run in a valid project | ||
| // preRunEnvUnsetCommandFunc determines if the command is run in a valid project | ||
| // and configures flags | ||
| func preRunEnvRemoveCommandFunc(ctx context.Context, clients *shared.ClientFactory, cmd *cobra.Command) error { | ||
| func preRunEnvUnsetCommandFunc(ctx context.Context, clients *shared.ClientFactory, cmd *cobra.Command) error { | ||
| clients.Config.SetFlags(cmd) | ||
| return cmdutil.IsValidProjectDirectory(clients) | ||
| } | ||
|
|
||
| // runEnvRemoveCommandFunc removes an environment variable from an app | ||
| func runEnvRemoveCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, args []string) error { | ||
| // runEnvUnsetCommandFunc removes an environment variable from an app | ||
| func runEnvUnsetCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, args []string) error { | ||
| ctx := cmd.Context() | ||
|
|
||
| // Hosted apps require selecting an app before gathering variable inputs. | ||
|
|
@@ -106,7 +107,7 @@ func runEnvRemoveCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, | |
| return err | ||
| } | ||
| if len(variables) <= 0 { | ||
| clients.IO.PrintTrace(ctx, slacktrace.EnvRemoveSuccess) | ||
| clients.IO.PrintTrace(ctx, slacktrace.EnvUnsetSuccess) | ||
| clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{ | ||
| Emoji: "evergreen_tree", | ||
| Text: "App Environment", | ||
|
|
@@ -135,7 +136,7 @@ func runEnvRemoveCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, | |
| return err | ||
| } | ||
| if len(dotEnv) <= 0 { | ||
| clients.IO.PrintTrace(ctx, slacktrace.EnvRemoveSuccess) | ||
| clients.IO.PrintTrace(ctx, slacktrace.EnvUnsetSuccess) | ||
| clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{ | ||
| Emoji: "evergreen_tree", | ||
| Text: "App Environment", | ||
|
|
@@ -177,7 +178,7 @@ func runEnvRemoveCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, | |
| if err != nil { | ||
| return err | ||
| } | ||
| clients.IO.PrintTrace(ctx, slacktrace.EnvRemoveSuccess) | ||
| clients.IO.PrintTrace(ctx, slacktrace.EnvUnsetSuccess) | ||
| clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{ | ||
| Emoji: "evergreen_tree", | ||
| Text: "App Environment", | ||
|
|
@@ -190,7 +191,7 @@ func runEnvRemoveCommandFunc(clients *shared.ClientFactory, cmd *cobra.Command, | |
| if err != nil { | ||
| return err | ||
| } | ||
| clients.IO.PrintTrace(ctx, slacktrace.EnvRemoveSuccess) | ||
| clients.IO.PrintTrace(ctx, slacktrace.EnvUnsetSuccess) | ||
| clients.IO.PrintInfo(ctx, false, "\n%s", style.Sectionf(style.TextSection{ | ||
| Emoji: "evergreen_tree", | ||
| Text: "App Environment", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,18 +26,18 @@ While the `.env` file should **never** be committed to source control for securi | |
|
|
||
| ### Storing deployed environment variables {#deployed-env-vars} | ||
|
|
||
| When your app is [deployed](/tools/deno-slack-sdk/guides/deploying-to-slack), it will no longer use the `.env` file. Instead, you will have to add the environment variables using the [`env add`](/tools/slack-cli/reference/commands/slack_env_add) command. Environment variables added with `env add` will be made available to your deployed app's [custom functions](/tools/deno-slack-sdk/guides/creating-custom-functions) just as they are locally; see examples in the next section. | ||
| When your app is [deployed](/tools/deno-slack-sdk/guides/deploying-to-slack), it will no longer use the `.env` file. Instead, you will have to add the environment variables using the [`env set`](/tools/slack-cli/reference/commands/slack_env_set) command. Environment variables added with `env set` will be made available to your deployed app's [custom functions](/tools/deno-slack-sdk/guides/creating-custom-functions) just as they are locally; see examples in the next section. | ||
|
Member
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. praise: The power of the docs being part of the repo. Thanks for making this sweeping change so smooth! |
||
|
|
||
| For the above example, we could run the following command before deploying our app: | ||
|
|
||
| ```zsh | ||
| slack env add MY_ENV_VAR asdf1234 | ||
| slack env set MY_ENV_VAR asdf1234 | ||
| ``` | ||
|
|
||
| If your token contains non-alphanumeric characters, wrap it in quotes like this: | ||
|
|
||
| ```zsh | ||
| slack env add SLACK_API_URL "https://dev<yournumber>.slack.com/api/" | ||
| slack env set SLACK_API_URL "https://dev<yournumber>.slack.com/api/" | ||
| ``` | ||
|
|
||
| Your environment variables are always encrypted before being stored on our servers and will be automatically decrypted when you use them—including when listing environment variables with `slack env list`. | ||
|
|
@@ -145,14 +145,14 @@ SLACK_DEBUG=true | |
| For deployed apps, run the following command before deployment: | ||
|
|
||
| ``` | ||
| slack env add SLACK_DEBUG true | ||
| slack env set SLACK_DEBUG true | ||
| ``` | ||
|
|
||
| ## Included local and deployed variables {#included} | ||
|
|
||
| Slack provides two environment variables by default, `SLACK_WORKSPACE` and `SLACK_ENV`. The workspace name is specified by `SLACK_WORKSPACE` and `SLACK_ENV` provides a distinction between the `local` and `deployed` app. Use these values if you want to have different values based on the workspace or environment that the app is installed in. | ||
|
|
||
| These variables are automatically included when generating the manifest or triggers only. For access from within a custom function, these variables can be set from the `.env` file or with the [`env add`](/tools/slack-cli/reference/commands/slack_env_add) command. | ||
| These variables are automatically included when generating the manifest or triggers only. For access from within a custom function, these variables can be set from the `.env` file or with the [`env set`](/tools/slack-cli/reference/commands/slack_env_set) command. | ||
|
|
||
| A custom `WorkspaceMapSchema` can be created and used with these variables to decide which values to use for certain instances of an app. This can be used as an alternative to a local `.env` file or in conjunction with it. The following snippet works well for inclusion in your app manifest, or for triggers (for example, to change event trigger channel IDs): | ||
|
|
||
|
|
||
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.
praise: Nice catch!