Skip to content

-? prints the usage, and the first of -?, -h and -V is the whole command, as in Graphviz - #161

Open
closer-claudio wants to merge 1 commit into
mainfrom
claudio/20261122-help-version
Open

closer-claudio wants to merge 1 commit into
mainfrom
claudio/20261122-help-version

Conversation

@closer-claudio

Copy link
Copy Markdown
Contributor

-? is the help flag of Graphviz's dot, and the command did not take it: it called it an unknown flag. It now prints the usage on standard output and exits 0, as -h does (which Graphviz's dot does not have, and which stays).

The order of the flags follows Graphviz's dot too. That command acts on -? and -V where it meets them and reads nothing after. Measured beside Graphviz's dot 16.1.1:

Command line Graphviz before now
-? usage, 0 unknown flag, 1 usage, 0
-? -Tnope usage, 0 1 usage, 0
-V -Tnope version, 0 1 version, 0
-V -? version, 0 usage, 0 version, 0
-Tnope -? 1 1 1

The command read the whole line first, so a bad flag anywhere won over the help, and -h won over -V wherever each stood. parseArgs now returns at the first of -?, -h, --help, -V, --version.

Tests: TestTheFirstOfHelpAndVersionIsTheWholeCommand holds seven orderings, each also run against the native dot when DOT_ORACLE names one (all seven agree with 16.1.1); the contract table gains -? and the orderings with their streams, and TestParseArgs the same at the parser.

Not here: -V still prints this command's module version on standard output. Graphviz's dot prints dot - graphviz version … on standard error; following it needs the engine to say which Graphviz it embeds (forkcloser/go-graphviz#253) and comes after it.

…and, as in Graphviz

Graphviz's dot takes -? for its help: usage on standard output, exit 0.
The command called it an unknown flag. It now takes -? as it takes -h
(which Graphviz's dot does not have, and which stays).

Graphviz's dot acts on -? and -V where it meets them and reads nothing
after: `dot -? -Tnope` and `dot -V -Tnope` exit 0, `dot -Tnope -?` exits
1, `dot -V -?` prints the version. The command read the whole line first,
so a bad flag anywhere won over the help, and -h won over -V wherever
each stood. parseArgs now returns at the first of them.

TestTheFirstOfHelpAndVersionIsTheWholeCommand holds seven orderings, each
also run against the native dot under DOT_ORACLE (all seven agree with
16.1.1); the contract table gains -? and the orderings with their
streams, TestParseArgs the same at the parser.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: closer-claudio <claudio@farcloser.world>
@closer-claudio

Copy link
Copy Markdown
Contributor Author

Reviewed at 8f5a5a1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant