Skip to content

fail when the cli is given an unknown option - #339

Merged
0xShug0 merged 2 commits into
0xShug0:mainfrom
avionicharshit-byte:fix/warn-on-unused-cli-args
Aug 29, 2026
Merged

fail when the cli is given an unknown option#339
0xShug0 merged 2 commits into
0xShug0:mainfrom
avionicharshit-byte:fix/warn-on-unused-cli-args

Conversation

@avionicharshit-byte

@avionicharshit-byte avionicharshit-byte commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

fixes #338. a misspelled option is currently dropped without a word, so --bakend cuda runs on cpu and exits 0.

find_arg, has_arg and collect_args record the name they were asked for, and require_known_args refuses anything on the command line that nobody asked about. there is no second list of flags to keep in sync, a new option is recognised the moment its lookup is added.

value-taking and boolean lookups are recorded separately because only the first kind consumes the next argument. without that split a typo sitting after a boolean flag gets swallowed as its value, and a value that happens to start with -- gets reported as an option. both were real, both are covered below.

it is a hard error, and it runs before the model does any work. the message goes to stderr, stdout stays empty and the exit code is 1. checking before the run rather than after it means every option has to be read before the command branches, which is what most of this diff is: the output paths, --input-format, --json and the batch and workflow options are now read up front and passed down, instead of being read halfway through or after the session has already finished.

two real bugs fell out of doing that. has_vad_chunk_option short circuited on ||, so three --vad-chunk-* options were never looked up and got reported as unknown. seven more options are only read on a single code path, so they were rejected on every other one. both are fixed, and all 98 options the cli looks up are swept below with no false rejects.

built at e73c980 on macos arm64, cmake -DAUDIOCPP_MODEL_SET=custom -DAUDIOCPP_MODELS=citrinet_asr --target audiocpp_cli:

command before after
--task asr --family citrinet_asr --model <path> --audio speech.wav exit 0, 3.1s exit 0, 3.1s, identical stdout
--task asr ... --bakend cuda ran on cpu, exit 0 unknown option: --bakend, exit 1, 0.13s, no stdout
--task asr ... --sesion-option a=b silent, exit 0 unknown option: --sesion-option, exit 1
--task asr ... --foo --bar silent, exit 0 unknown options: --foo --bar, exit 1
--task asr ... --metrics --foo silent, exit 0 unknown option: --foo, exit 1
--task asr ... --log-file --weird-looking-value exit 0 exit 0, the value is not an option
--task asr ... --backend cpu --threads 2 exit 0 exit 0
--list-loaders silent, exit 0 silent, exit 0
--list-loaders --bakend cuda silent, exit 0 warning: ignored option: --bakend, exit 0

parity against main: stdout is byte for byte identical on every valid command tested, covering --list-loaders, --list-loaders --json, --list-devices, --list-pipelines, --help, --help --task asr, --inspect, offline asr, offline vad, vad chunk outputs, batch audio dir, streaming and stdin pcm. output files written by --out-dir, --text-out, --words-out, --segments-out, --turns-out, --vad-chunks-out and --batch-manifest-out are identical too.

what this does not do: the informational commands return before the rest of the options are read, so on --help, --list-* and --inspect the cli cannot tell a misspelling from an option that simply does not apply to that command. rejecting both would break anything that runs --list-devices --backend cuda today, so those stay a warning and exit 0. making them strict as well needs the whole option set parsed up front before dispatch, which is a bigger change than this one and easy to do as a follow up.

@0xShug0

0xShug0 commented Aug 29, 2026

Copy link
Copy Markdown
Owner

@avionicharshit-byte Good catch, and thanks for the fix!

For warning vs hard failure: I think this should be a hard failure instead of a warning. Could you update the PR?

@avionicharshit-byte
avionicharshit-byte force-pushed the fix/warn-on-unused-cli-args branch from 11f16e8 to 912088c Compare August 29, 2026 17:39
@avionicharshit-byte avionicharshit-byte changed the title warn when the cli is given an unknown option fail when the cli is given an unknown option Aug 29, 2026
@avionicharshit-byte

avionicharshit-byte commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

@0xShug0 done , its a hard error now

audiocpp_cli failed: unknown option: --bakend on stderr , exit 1 , stdout stays empty

the check also moved ahead of the run rather than after it , a typo now fails in 0.13s instead of running a full transcription first and failing at the end with the output already on stdout

moving it earlier meant every option has to be read before the command branches , and two real bugs fell out of that. has_vad_chunk_option short circuited on || so three --vad-chunk-* options were never looked up and got rejected as unknown. seven more (--json , --input-rate , --input-channels , --batch-merge-audio , --batch-audio-role , --audio-converter , --workflow-input) are only read on one path , so they were rejected everywhere else. both fixed , and i swept all 98 options the cli looks up , zero false rejects

command before after
--task asr ... --audio speech.wav exit 0 , 3.1s exit 0 , 3.1s , identical stdout
--task asr ... --bakend cuda ran on cpu , exit 0 unknown option: --bakend , exit 1 , 0.13s , no stdout
--task asr ... --sesion-option a=b silent , exit 0 unknown option: --sesion-option , exit 1
--task asr ... --foo --bar silent , exit 0 unknown options: --foo --bar , exit 1
--task asr ... --metrics --foo silent , exit 0 unknown option: --foo , exit 1
--task asr ... --log-file --weird-looking-value exit 0 exit 0 , the value is not an option
--list-loaders --bakend cuda silent , exit 0 warning: ignored option: --bakend , exit 0

the one case i could not make strict is the informational commands. --help , --list-* and --inspect return before the rest of the options are read , so there the cli genuinely cannot tell --bakend from --backend , one is a typo and the other just does not apply to that command. rejecting both would break anything doing --list-devices --backend cuda today , so those stay a warning. making them strict too needs the whole option set parsed up front before dispatch , happy to do that if you want it

built on macos arm64 with -DAUDIOCPP_MODEL_SET=custom -DAUDIOCPP_MODELS=citrinet_asr , stdout byte for byte identical to main on every valid command i tested including batch , streaming , stdin pcm and the vad chunk outputs

@0xShug0
0xShug0 merged commit fb5bace into 0xShug0:main Aug 29, 2026
6 checks passed
@0xShug0

0xShug0 commented Aug 29, 2026

Copy link
Copy Markdown
Owner

@avionicharshit-byte Thanks! PR merged.

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.

audiocpp_cli silently ignores unknown options

2 participants