Skip to content

Commit dd4dd7f

Browse files
fix: suppress update notification when structured output format is requested
When --format=json or --output=json (or csv/yaml) is passed, the update notification message was printed to stderr which could break machine-readable output parsing. This adds a check in PersistentPreRun to skip the update notification when a structured output format flag is explicitly set. Co-Authored-By: Vlad Matsiiako <vm265@cornell.edu>
1 parent 9c2759f commit dd4dd7f

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

packages/cmd/root.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@ func RootCmdStdoutWriter() io.Writer {
6161
return &rootCmdStdoutWriter{}
6262
}
6363

64+
// isStructuredOutputRequested checks whether the command has a --format or --output
65+
// flag explicitly set to a machine-readable format (json, csv, yaml). When true,
66+
// human-oriented messages like update notifications should be suppressed to avoid
67+
// breaking parsers that consume the CLI output.
68+
func isStructuredOutputRequested(cmd *cobra.Command) bool {
69+
structuredFormats := map[string]bool{"json": true, "csv": true, "yaml": true}
70+
71+
for _, flagName := range []string{"format", "output"} {
72+
if f := cmd.Flags().Lookup(flagName); f != nil && f.Changed {
73+
if structuredFormats[strings.ToLower(f.Value.String())] {
74+
return true
75+
}
76+
}
77+
}
78+
return false
79+
}
80+
6481
// Execute adds all child commands to the root command and sets flags appropriately.
6582
// This is called by main.main(). It only needs to happen once to the RootCmd.
6683
func Execute() {
@@ -88,7 +105,7 @@ func init() {
88105
config.INFISICAL_URL = util.AppendAPIEndpoint(config.INFISICAL_URL)
89106

90107
// util.DisplayAptInstallationChangeBannerWithWriter(silent, cmd.ErrOrStderr())
91-
if !util.IsRunningInDocker() && !silent {
108+
if !util.IsRunningInDocker() && !silent && !isStructuredOutputRequested(cmd) {
92109
util.CheckForUpdateWithWriter(cmd.ErrOrStderr())
93110
}
94111

0 commit comments

Comments
 (0)