Repository navigation
How should a CLI select its default command on empty or global-flags-only invocations? #1442
Replies: 2 comments 2 replies
|
This is a reasonable use case. My preference would be an explicit opt-in policy, preserving today's Your diagnosis matches the implementation and documented semantics: The important requirement is selecting Your two-parse adapter is a reasonable temporary workaround for this CLI, but I wouldn't make that the general solution. Besides maintaining the subcommand list, prepending I'd favor a separate setting—illustratively, The boundaries I'd suggest are:
This should be shared command-selection semantics, before fallback resolution and validation, with matching reference/Rust/Go conformance tests covering both routing and the resulting values and requirements. A Go-only handler helper would leave the underlying semantic gap unresolved. This assessment is based on reviewing the source and OATs adapter; I haven't run a reproduction. This comment was AI-generated using OpenAI Codex. |
Uh oh!
There was an error while loading. Please reload this page.
Use case
We are experimenting with Usage's Go generator in OATs, a test runner. Its normal invocation is just
oats: discover configuration and run tests.oats -vmust do the same with verbosity enabled; an explicitoats runis equivalent.We understand that
default_subcommandcurrently routes an unmatched first word rather than selecting a child when no command word is present. We would like advice on the intended way to express this application behavior, rather than silently introduce different semantics in Go.A reduced version of the spec is:
oatsrunoats -vrun, with verbosityoats ./casesrunwith a pathoats --timeout 2mrunthrough default flag routingoats listlistoats --helpThis is about more than calling the run handler: selecting
runmust also apply its environment values, defaults, and validation. Root help/version should still exit without executing tests or validating run-only requirements.Current workaround
Our adapter calls generated
Parse, checks that every subcommand pointer is nil, and then parses again withrunprepended. That works for our current CLI but means maintaining a list of every command and performing a second parse. We would prefer to avoid that glue and keep option resolution owned by Usage.Questions
runcommand?default_subcommandbehavior, adding a separate explicit policy, or keeping this as application-level dispatch with a supported helper?We are happy to contribute an implementation and conformance tests once the direction is clear. We are not assuming the existing behavior is a bug or proposing a Go-only change to the shared grammar; an idiomatic alternative would be just as useful.
AI-assisted discussion prepared using OpenAI Codex.
All reactions