Skip to content

Commit

Permalink
fix: remove --json-output flag from logs command, fixes #962 (#5695)…
Browse files Browse the repository at this point in the history
… [skip ci]
  • Loading branch information
GuySartorelli committed Jan 26, 2024
1 parent 6be1176 commit 9d60b74
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cmd/ddev/cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ func init() {
DdevLogsCmd.Flags().BoolVarP(&timestamp, "time", "t", false, "Add timestamps to logs")
DdevLogsCmd.Flags().StringVarP(&serviceType, "service", "s", "web", "Defines the service to retrieve logs from. [e.g. web, db]")
DdevLogsCmd.Flags().StringVarP(&tail, "tail", "", "", "How many lines to show")
RootCmd.AddCommand(DdevLogsCmd)

// JSON formatted output isn't supported, so we should hide the global --json-output flag
// We have to do that within the help function, since the global flag hasn't been added yet during init()
originalHelpFunc := DdevLogsCmd.HelpFunc()
DdevLogsCmd.SetHelpFunc(func(command *cobra.Command, strings []string) {
_ = command.Flags().MarkHidden("json-output")
originalHelpFunc(command, strings)
})
// We need to do the same with the flag error function in case flags can't be parsed correctly,
// because that output (although identical to the help function) is generated separately.
originalErrorFunc := DdevLogsCmd.FlagErrorFunc()
DdevLogsCmd.SetFlagErrorFunc(func(command *cobra.Command, err error) error {
_ = command.Flags().MarkHidden("json-output")
return originalErrorFunc(command, err)
})

RootCmd.AddCommand(DdevLogsCmd)
}

0 comments on commit 9d60b74

Please sign in to comment.