@@ -184,6 +184,7 @@ func SetupCommands(version string) {
184
184
185
185
// Config Command (was: secrets)
186
186
configSetCmd .Flags ().BoolP ("name" , "n" , false , "name of the config (backwards compat)" )
187
+ configSetCmd .Flags ().BoolP ("env" , "e" , false , "set the config from an environment variable" )
187
188
_ = configSetCmd .Flags ().MarkHidden ("name" )
188
189
189
190
configCmd .AddCommand (configSetCmd )
@@ -734,12 +735,13 @@ var configCmd = &cobra.Command{
734
735
}
735
736
736
737
var configSetCmd = & cobra.Command {
737
- Use : "create CONFIG [file]" , // like Docker
738
+ Use : "create CONFIG [file|- ]" , // like Docker
738
739
Annotations : authNeededAnnotation ,
739
740
Args : cobra .RangeArgs (1 , 2 ),
740
741
Aliases : []string {"set" , "add" , "put" },
741
742
Short : "Adds or updates a sensitive config value" ,
742
743
RunE : func (cmd * cobra.Command , args []string ) error {
744
+ fromEnv , _ := cmd .Flags ().GetBool ("env" )
743
745
744
746
// Make sure we have a project to set config for before asking for a value
745
747
_ , err := client .LoadProjectName (cmd .Context ())
@@ -755,7 +757,16 @@ var configSetCmd = &cobra.Command{
755
757
}
756
758
757
759
var value string
758
- if len (parts ) == 2 {
760
+ if fromEnv {
761
+ if len (args ) == 2 || len (parts ) == 2 {
762
+ return errors .New ("cannot specify config value or input file when using --env" )
763
+ }
764
+ var ok bool
765
+ value , ok = os .LookupEnv (name )
766
+ if ! ok {
767
+ return fmt .Errorf ("environment variable %q not found" , name )
768
+ }
769
+ } else if len (parts ) == 2 {
759
770
// Handle name=value; can't also specify a file in this case
760
771
if len (args ) == 2 {
761
772
return errors .New ("cannot specify both config value and input file" )
0 commit comments