@@ -182,6 +182,7 @@ func SetupCommands(version string) {
182
182
183
183
// Config Command (was: secrets)
184
184
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" )
185
186
_ = configSetCmd .Flags ().MarkHidden ("name" )
186
187
187
188
configCmd .AddCommand (configSetCmd )
@@ -716,12 +717,13 @@ var configCmd = &cobra.Command{
716
717
}
717
718
718
719
var configSetCmd = & cobra.Command {
719
- Use : "create CONFIG [file]" , // like Docker
720
+ Use : "create CONFIG [file|- ]" , // like Docker
720
721
Annotations : authNeededAnnotation ,
721
722
Args : cobra .RangeArgs (1 , 2 ),
722
723
Aliases : []string {"set" , "add" , "put" },
723
724
Short : "Adds or updates a sensitive config value" ,
724
725
RunE : func (cmd * cobra.Command , args []string ) error {
726
+ fromEnv , _ := cmd .Flags ().GetBool ("env" )
725
727
726
728
// Make sure we have a project to set config for before asking for a value
727
729
_ , err := client .LoadProjectName (cmd .Context ())
@@ -737,7 +739,16 @@ var configSetCmd = &cobra.Command{
737
739
}
738
740
739
741
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 {
741
752
// Handle name=value; can't also specify a file in this case
742
753
if len (args ) == 2 {
743
754
return errors .New ("cannot specify both config value and input file" )
0 commit comments