Repository navigation
feat: self-correcting flag/command errors, global --fields, query window notes - #217
Merged
Merged
Conversation
…dow notes Callers frequently guess flag and verb names by analogy with a sibling command. The errors now carry the candidates, so the next call can be right without a separate --help round trip: - Unknown flag: lists the closest flag names, the command's own flags and the global flags (root FlagErrorFunc, inherited by curated and generated commands). Other flag errors pass through unchanged. - Unknown command: suggests siblings, then single-record verb synonyms (get/info/infos/detail), then any leaf in the whole tree whose path contains the token on hyphen-token boundaries (`silence` -> `channel silence-rule-list`, `monit-datasource` -> `monit datasource-list`), and lists the level's commands. The check now runs before cobra dispatch, so `<group> <typo> --help` errors instead of printing the group's help and exiting 0. - `--version` is accepted and prints the `version` line. --fields is now a global output flag: json/toon output of any command is projected to the named top-level fields (each row of a list, or the keys of a single record), before the 16 KiB bound is applied. A name matching no key is reported on stderr with the keys that exist; acknowledgements and raw bodies print unchanged with a note; non-projectable shapes are an error. Commands with their own --fields keep it. Windowed queries announce on stderr the window they sent, in the local timezone, with its span and its end relative to now (`note: window ..(1h, ends in 7h)`), which makes a wrong default or a timezone slip visible. This covers the curated windowed verbs, monit-query's execution window, and generated --start-time/--end-time pairs. `incident list` with only open --progress states and `alert list --active` default to 30d instead of 24h when --since is not given, since open records are often older than a day. skilldoc: the dump now carries the root's flags; the validator checks the flags of a bare `fduty --flag` example against them and takes global flags from the dump instead of a hand-kept list.
A bare `fduty --bogus` reports an unknown flag; `fduty --json` is valid.
Contributor
Author
|
Checked against a live test environment with read-only commands only, comparing this branch to 1.
2.
3.
It returned 4 frames.
It returned
4. Suggestions
5.
In every case above, stdout stayed valid JSON/toon, and all the notes went to stderr. |
…re it does not apply A defaulted lookback --since (24h, or 30d for open-only incident and active alert lists) now spans back from the parsed --until instead of from now. With --until +1d the 30d default used to produce a 31-day window, which the list endpoints reject; a past --until with the 24h default produced an inverted window. timeutil.Lookback recognizes the past-relative duration form (and rejects "+" offsets, which the day shorthand expansion would otherwise accept). The "--fields does not apply" note moves to the root PersistentPostRun, driven by whether a projection ran. Commands that print their own output (version, config show) and table mode now get the note too, instead of ignoring --fields silently.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Callers (people typing from memory, scripts, agents) often guess a flag or verb name by analogy with a sibling command. This PR makes those errors list the valid candidates so the next call can be correct, adds
--fieldsto every command's structured output, and prints the time window a query actually sent.Unknown flag / command errors list candidates
FlagErrorFuncis inherited by every curated and generated command. Only unknown-flag errors are extended; a bad value for a known flag keeps pflag's message.get/info/infos/detail)flashduty alert lsit --helpprinted thealerthelp and exited 0, because cobra handles--helpbefore anyArgsvalidator runs.--versionnow works and prints the same line asflashduty version.--fieldson every command--fieldsis now a global output flag, like--output-format. In json/toon mode it keeps the named top-level fields of each list row, or of a single record. List envelope keys such astotaland cursors are kept.omitemptykey can be absent from a whole page.--fieldscannot project prints unchanged, with a stderr note saying so: acknowledgements, raw (CSV/file) bodies, table mode, and commands that print their own output (version,config show). One post-run hook emits the note, so no command ignores the flag silently. A list of scalars is an error.--fieldskeep it, since the local flag shadows the global one. That covers incident list/detail/similar, alert list, alert-event list and others with default projections, plusmonit rule-update-fields, where--fieldsis a request field.Query window notes
monit-query(itsexecution.from_ms/to_ms)--start-time/--end-timepairs, via cligenincident list --progress Triggered[,Processing]andalert list --activenow default to 30d instead of 24h when--sinceis not given. Open records are often older than a day, and 30d is the widest window the list endpoints accept.--since(24h or 30d) now spans back from--until, not from now. Before,--until +1dwith the 30d default produced a 31-day window, which the server rejects. A past--untilwith the 24h default produced an inverted window.skilldoc
`fduty --flag`example against the root flags. Before, such examples were skipped as prose.Behavior changes
For release notes:
incident list --progress Triggered(orProcessing, or both) andalert list --activenow query the last 30 days when--sinceis not given, instead of the last 24 hours. Results can contain more rows than before. Pass--since 24hfor the previous window.--sinceis measured from--until. When only--untilis given, the default lookback ends at--untilinstead of at the current time.note: window ...line to stderr: incident, alert, alert-event, change, audit, insight, oncall,monit-query, and generated commands with--start-time/--end-time. stdout is unchanged. Callers that merge the streams (2>&1) and parse the result as JSON should read stdout only.--help.flashduty <group> <typo> --helpnow prints the unknown-command error with suggestions and exits 1. Before, it printed the group's help and exited 0.--fieldsis a global flag. Commands that did not accept it before now project json/toon output, or print a stderr note when the flag does not apply. Commands with their own--fieldsbehave as before.--versionis accepted on the root command.Test plan
make check(gofmt/gci, golangci-lint v2.11.4 with 0 issues,go test -race ./..., build): all pass.make check-cards: cards OK.make gen-cardsandgo run ./internal/cmd/cligenproduce no further diff.suggest_test.go: flag and command suggestions;--helpafter a typo; lazyhelp/completion/__completestill dispatch;--version.window_test.go: note text with a pinned clock and timezone; 30d defaults per--progress/--activecombination; default--sinceanchored at--until +1d(30d span) and at a past--until(24h span); generated andmonit-querynotes; stdout purity.outputfields_test.go: generated list envelope, curated detail, unmatched-name note, table mode, acknowledgement note,version/config show/ table-mode notes, local--fieldsshadowing, shape error.parse_test.go:Lookbackaccepts past durations only (rejects+1d,now, dates, epochs).validate_test.go: a bogus root flag fails;--helpand--versionpass.🤖 Generated with Claude Code