Skip to content

Commit 97e5070

Browse files
Merge pull request #166 from Infisical/devin/1774808110-suppress-update-notice-json-format
fix: suppress update notification when --format=json is passed
2 parents 9c2759f + ebe35ca commit 97e5070

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", "report-format"} {
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)