Skip to content

Commit faa3904

Browse files
committed
Set config from env
1 parent 97c70c1 commit faa3904

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/cmd/cli/command/commands.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ func SetupCommands(version string) {
182182

183183
// Config Command (was: secrets)
184184
configSetCmd.Flags().BoolP("name", "n", false, "name of the config (backwards compat)")
185+
configSetCmd.Flags().BoolP("env", "e", false, "set the config from an environment variable")
185186
_ = configSetCmd.Flags().MarkHidden("name")
186187

187188
configCmd.AddCommand(configSetCmd)
@@ -716,12 +717,13 @@ var configCmd = &cobra.Command{
716717
}
717718

718719
var configSetCmd = &cobra.Command{
719-
Use: "create CONFIG [file]", // like Docker
720+
Use: "create CONFIG [file|-]", // like Docker
720721
Annotations: authNeededAnnotation,
721722
Args: cobra.RangeArgs(1, 2),
722723
Aliases: []string{"set", "add", "put"},
723724
Short: "Adds or updates a sensitive config value",
724725
RunE: func(cmd *cobra.Command, args []string) error {
726+
fromEnv, _ := cmd.Flags().GetBool("env")
725727

726728
// Make sure we have a project to set config for before asking for a value
727729
_, err := client.LoadProjectName(cmd.Context())
@@ -737,7 +739,16 @@ var configSetCmd = &cobra.Command{
737739
}
738740

739741
var value string
740-
if len(parts) == 2 {
742+
if fromEnv {
743+
if len(args) == 2 || len(parts) == 2 {
744+
return errors.New("cannot specify config value or input file when using --env")
745+
}
746+
var ok bool
747+
value, ok = os.LookupEnv(name)
748+
if !ok {
749+
return fmt.Errorf("environment variable %q not found", name)
750+
}
751+
} else if len(parts) == 2 {
741752
// Handle name=value; can't also specify a file in this case
742753
if len(args) == 2 {
743754
return errors.New("cannot specify both config value and input file")

0 commit comments

Comments
 (0)