Skip to content

Commit ef93859

Browse files
committed
Add --no-warn-conflicts flag
1 parent 54840a4 commit ef93859

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

cmd/exec.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ var strictValue string
2424
// Default value to expect in strict mode
2525
const strictValueDefault = "chamberme"
2626

27+
// When true, suppress warnings about conflicting environment variables
28+
var noWarnConflicts bool
29+
2730
// execCmd represents the exec command
2831
var execCmd = &cobra.Command{
2932
Use: "exec <service...> -- <command> [<arg...>]",
@@ -58,6 +61,11 @@ Given a secret store like this:
5861
$ HOME=/tmp DB_USERNAME=chamberme DB_PASSWORD=chamberme chamber exec --strict --pristine service exec -- env
5962
DB_USERNAME=root
6063
DB_PASSWORD=hunter22
64+
65+
--no-warn-conflicts suppresses warnings when services overwrite environment variables
66+
67+
$ chamber exec --no-warn-conflicts service1 service2 -- env
68+
# No warnings about conflicting keys between service1 and service2
6169
`,
6270
}
6371

@@ -68,6 +76,7 @@ only inject secrets for which there is a corresponding env var with value
6876
<strict-value>, and fail if there are any env vars with that value missing
6977
from secrets`)
7078
execCmd.Flags().StringVar(&strictValue, "strict-value", strictValueDefault, "value to expect in --strict mode")
79+
execCmd.Flags().BoolVar(&noWarnConflicts, "no-warn-conflicts", false, "suppress warnings when services overwrite environment variables (useful when conflicts are expected)")
7180
RootCmd.AddCommand(execCmd)
7281
}
7382

@@ -123,8 +132,10 @@ func execRun(cmd *cobra.Command, args []string) error {
123132
return fmt.Errorf("Failed to list store contents: %w", err)
124133
}
125134

126-
for _, c := range collisions {
127-
fmt.Fprintf(os.Stderr, "warning: service %s overwriting environment variable %s\n", service, c)
135+
if !noWarnConflicts {
136+
for _, c := range collisions {
137+
fmt.Fprintf(os.Stderr, "warning: service %s overwriting environment variable %s\n", service, c)
138+
}
128139
}
129140
}
130141
}

0 commit comments

Comments
 (0)