Skip to content

Commit f4f14c9

Browse files
authored
Merge pull request #608 from DefangLabs/lio-config-from-env
Set config from env
2 parents e1355d6 + faa3904 commit f4f14c9

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
@@ -184,6 +184,7 @@ func SetupCommands(version string) {
184184

185185
// Config Command (was: secrets)
186186
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")
187188
_ = configSetCmd.Flags().MarkHidden("name")
188189

189190
configCmd.AddCommand(configSetCmd)
@@ -734,12 +735,13 @@ var configCmd = &cobra.Command{
734735
}
735736

736737
var configSetCmd = &cobra.Command{
737-
Use: "create CONFIG [file]", // like Docker
738+
Use: "create CONFIG [file|-]", // like Docker
738739
Annotations: authNeededAnnotation,
739740
Args: cobra.RangeArgs(1, 2),
740741
Aliases: []string{"set", "add", "put"},
741742
Short: "Adds or updates a sensitive config value",
742743
RunE: func(cmd *cobra.Command, args []string) error {
744+
fromEnv, _ := cmd.Flags().GetBool("env")
743745

744746
// Make sure we have a project to set config for before asking for a value
745747
_, err := client.LoadProjectName(cmd.Context())
@@ -755,7 +757,16 @@ var configSetCmd = &cobra.Command{
755757
}
756758

757759
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 {
759770
// Handle name=value; can't also specify a file in this case
760771
if len(args) == 2 {
761772
return errors.New("cannot specify both config value and input file")

0 commit comments

Comments
 (0)