Repository navigation
watch: print usage for help and refuse arguments it cannot honour - #385
Open
NopeCharon wants to merge 1 commit into
Open
NopeCharon wants to merge 1 commit into
NopeCharon wants to merge 1 commit into
Conversation
Every other observability subcommand (audit, stats, trace, doctor, and the policy, dlp and ratelimit commands) has a usage helper and handles "help" before doing any work. RunWatch had neither. It never looked at its positionals, so `solongate watch help`, `watch -h` and `watch --help` all started the same blocking live tail as a bare `solongate watch`, which then had to be interrupted with Ctrl+C, and watch's own flags were documented nowhere in the CLI. RunWatch now: - prints watchUsage(), listing --filter, --tool, --local-only, --cloud-only and --json, for `help`, `-h` or `--help`, and exits 0; - refuses any other positional with cliutil.UnknownSub and the usage, as trace and audit do, instead of ignoring it; - refuses a --filter that is not ALLOW or DENY (DENIED is still taken, as audit takes it), worded like audit's check. Before, a value such as `--filter blocked` was accepted and the tail silently matched nothing, forever; - refuses --local-only together with --cloud-only. Each turns off the other's source, so the pair polled nothing and printed nothing. All of these exit before the polling loop starts, since anything that reaches it runs until interrupted. The tests drive RunWatch under a context deadline, so a case that wrongly falls through to the loop fails with code 130 instead of hanging the suite. On main, the help and rejection cases all fail that way. Fixes solongate#179. Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
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.
Fixes #179.
Every other observability subcommand (
audit,stats,trace,doctor, and thepolicy,dlpandratelimitcommands) has a usage helper and handleshelpbefore doing any work.RunWatchhad neither. It never looked at its positionals, sosolongate watch help,watch -handwatch --helpall started the same blocking live tail as a baresolongate watch, which then had to be interrupted with Ctrl+C. Watch's own flags were documented nowhere in the CLI.Change
All in
packages/cli/observability/watch.go.RunWatchnow:watchUsage()forhelp,-hor--help, and exits 0. The usage lists--filter,--tool,--local-only,--cloud-onlyand--json, worded liketraceUsage.cliutil.UnknownSuband the usage, astraceandauditdo, instead of ignoring it.--filterthat is notALLOWorDENY, using the same wording asaudit --filter.DENIEDis still accepted, asauditaccepts it. Before,--filter blockedwas taken and the tail silently matched nothing, forever.--local-onlytogether with--cloud-only. Each one turns off the other's source, so the pair polled nothing and printed nothing.All of these exit before the polling loop starts, since anything that reaches the loop runs until interrupted. Valid invocations behave as before. Nothing on the decision path changes.
Tests
In
packages/cli/observability/watch_test.go. The helperrunWatchBrieflydrivesRunWatchunder a context deadline, so a case that wrongly falls through to the loop fails with code 130 instead of hanging the suite.TestRunWatchHelp:help,-hand--helpexit 0, print every flag, and never start the tail. All three fail onmain, where they run until the deadline.TestRunWatchRejectsBadUsage: an unknown positional, an unknown--filterand the conflicting--local-only --cloud-onlypair exit 1 with their message. All three fail onmain.TestRunWatchAcceptsFilterInAnyCase:deny,Allowanddeniedstill start the tail.I ran
go vet ./...(also withGOOS=windows) andgo test -count=1 ./observability/inpackages/clilocally on macOS.