Repository navigation
fix: report bad flags with the command's usage; add ruflet help <command> (CLI-12) - #78
Merged
Merged
Conversation
Adds test/cli_usage_test.rb, red on this commit: an unknown flag on every command prints that command's usage and exits 64 before anything runs; -h/--help after a command and `ruflet help <command>` print its help; `build --release apk` finds the target; `emulators --cold` cold boots; `run --device` is reserved while -d, --d and --de stay --desktop. The tests that pass here pin what must not change: every spelling of --desktop, debug's device spellings, and build/devices forwarding. Adds three H1 invocations, generated on this code: `build apk --release` for default_app and services_app, and services_app `build --release apk` (today: Unsupported build target).
…command>` CLI-12. Every command now reports a flag it does not read the same way: `ruflet <command>: <reason>`, a blank line and that command's help, on stderr, exit 64 (EX_USAGE, as flutter). No backtrace. - Commands that read their flags by exact match (version, create, new, install, doctor) are checked by Ruflet::CLI.run against their declared options before anything is fetched or written. - run, update, debug and emulators keep their OptionParser; its errors are rescued by the dispatcher and reported the same way. - build and devices still pass the flags they do not read to Flutter. -h/--help after a command, and `ruflet help <command>`, print that command's usage, summary, options and help sections, rendered from the registry. `ruflet help`, `ruflet --help` and `ruflet help <not a command>` still print the command list unchanged. `build apk --help` and `devices --help` still reach Flutter. Flag fixes: - `ruflet build --release apk` builds: when the first argument is a flag, the target is the one argument that names a target. Two such arguments after a flag are refused instead of guessed at. - `emulators --start --emulator ID --cold` cold boots (flutter emulators --launch ID --cold); --cold without --start is a usage error instead of a crash. emulators parses before looking up Flutter. - run: -d stays --desktop (D6), declared explicitly so the new `--device ID` does not make it ambiguous; --d and --de keep working. `run --device ID` says it is not supported yet instead of crashing. - debug: `--device ID` is declared beside --device-id (it already reached it as an abbreviation). - install: `--device=ID` is read; `-d` without a value is an error. H1: 32 goldens change, all -h/--help, --bogus-flag, `help build`, `--release apk`, `emulators --cold` or `run --device`; every documented invocation is unchanged. The R2 dispatch pins that recorded the old behavior are updated.
This was referenced Nov 8, 2026
This was referenced Nov 17, 2026
Conflict in cli/commands.rb's header comment only: main (#77) documents the forms OptionParser completes beyond the declarations; this branch documents that help and usage errors are rendered from them. Both kept.
…review) Review findings on #78, written against the old behavior first: - main's pin (#77) says `emulators -c` is --create and `debug -d` and `--dev` select --device-id. On this branch -c is ambiguous with --cold and the debug option's first long name is --device. The pin helper now builds its parser with the hidden switches too, as the switch-list check above it does. - `help --` and `--help --` listed the commands (exit 0); `build -- apk` said "Unsupported build target: --". Unit tests and H1 entries for them. - H1 entries for `emulators --c`, and for `--version -v`, `-v --verbose` and `version --anything`, whose change (exit 0 to 64) the next commit lists as a behavior change. The 7 new goldens were generated on main c444cbd (where a full --regenerate changed no other golden).
- `ruflet help --` and `--help --` list the commands again (exit 0): `--` ends the options, it is not a bad flag. - `ruflet build -- apk` is again "Unsupported build target: --"; nothing after `--` is taken as the build target, so `build --release -- apk` does not build either. - `emulators -c` and `--c` reach --create again: they are hidden switches of --create, as run's -d, --d and --de are of --desktop. - debug declares --device-id first, so -d and --dev select it as main's pin says; its help reads "--device-id ID, --device ID". Goldens regenerated for the listed behavior changes only: debug's help label (3), `install --device=ID` now installing on ID (main's #77 golden records it ignored), and the version words rejecting a flag (3).
…(CLI-12 review) The nine new H1 goldens were generated on main a9b5847; a full --regenerate there changed no other golden. The new handler tests fail on the previous head: rake ruflet:update[--help] (command_update called directly) raises HelpRequested, command_build(%w[--flavor web apk]) raises UsageError, and build treats a bare - as a flag.
… too ruflet_rails' rake tasks call Ruflet::CLI.command_update and command_build directly, so `rake "ruflet:update[--help]"` raised HelpRequested (exit 1) where main printed update's switch list (exit 0). Each handler that raises HelpRequested or UsageError now rescues it with Commands.report_stop, which prints what `ruflet <command>` prints and returns 0 or 64. OptionParser's own errors still reach a direct caller, as on main. extract_build_target! treats a bare `-` as an argument (Commands.flag?), so `build --self - apk` is again "Unsupported build target: -". Regenerated 6 of the goldens added in the previous commit: the rake help forms, `new my_app -h`, `create my_app --help` and `new -x`.
AdamMusa
added a commit
that referenced
this pull request
Nov 21, 2026
Port the build fixes onto the cli/build/* split (#75) and keep #77/#78's command registry: usage errors stay main's (exit 64), and the dispatcher, help heredoc and new-command checks this branch had are dropped in favour of main's. appbundle now gets aab's identity check, package rename and stale-output clearing without being renamed to aab.
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.
WP-00 CLI-12, built on the command registry (#77, merged). Base is
main; the branch mergesmainwith merge commits, so the diff againstmainis this PR alone (8 lib files, 3 test files, the H1 corpus and its README, and 51 goldens).What
Bad flags. A flag a command does not read prints
ruflet <command>: <reason>, a blank line and that command's help on stderr, and exits 64 (EX_USAGE, what flutter uses). No backtrace. Each registry entry says who reports it (unknown_flags:)::rejectRuflet::CLI.runchecks the arguments against the declared options, exactly, before the command runs, so nothing is fetched or written.:command:forwardflutter build <target>/flutter devices.Help.
ruflet help <command>and<command> -h/--helpprint that command's help, rendered from the registry; nothing runs or is fetched.build apk --helpanddevices --helpstill reach Flutter.ruflet help,ruflet --help,help bogusandhelp --print the command list as before.Direct calls. ruflet_rails' rake tasks call
command_build,command_updateandcommand_installwithoutRuflet::CLI.run. Each handler that raisesHelpRequestedorUsageError(run, update, debug, emulators, build) rescues it itself withCommands.report_stop, so a direct call prints whatruflet <command>prints and returns 0 or 64. OptionParser's own errors still reach a direct caller, as onmain.Flag fixes.
ruflet build --release apkbuilds, asbuild apk --releasedoes. When the first argument is a flag, the target is the one argument before any--that names a target. Two such arguments (--flavor web apk) are refused with exit 64 rather than guessed.emulators --start --emulator ID --coldrunsflutter emulators --launch ID --cold.run -dstays--desktop(declared explicitly;--d/--deare hidden aliases). Device selection is the long--device IDonly.run --device IDis reserved for CLI-01: it says it is not supported yet, points to Explorer andruflet install --device ID, and exits 1.debug --device IDis declared beside--device-id, which-dand--devstill select.install --device=IDis read.main:emulators -c/--creach--create;help --lists the commands;build -- apkandbuild --self - apkare the unsupported targets--and-; a help flag after--reaches the command (run main.rb -- --helpruns main.rb).Review fixes in this round
rake "ruflet:update[--help]"and[-h](also[--h],[--he]) print update's help and exit 0 again. The previous head raisedHelpRequested(exit 1). Direct calls of run, debug and emulators with-h, andcommand_build(%w[--flavor web apk]), also stop with help or a usage error instead of raising.build --self - apkis again "Unsupported build target: -" (exit 1):extract_build_target!usesCommands.flag?, so a bare-is an argument. The previous head built apk and passed-to Flutter.new/create NAME -h|--help,new -x, the rake help forms and direct handler calls.--reaches the command; a bare-is not a flag (help -,new my_app -); a prefix of a declared flag is unknown (install --dev X,install --verb,doctor --fi); and the direct calls above.Behavior changes
All are error paths or input that was ignored (X1 exceptions, D6 bug fixes). Against
main, 32 goldens change and 19 are added: 10 of the added goldens record new behavior and 9 matchmain. None of the 51 belongs to any of the 84 documented invocations indocs_coverage.rb.run/update/debug/emulatorswith a flag their parser rejects (--bogus-flag,run --port,run --web=1)OptionParsererror, exit 1run main.rb --device emulator-5554(also--dev)InvalidOption, exit 1emulators --cold(also--co) without--startInvalidOption, exit 1emulators --start --emulator ID --coldInvalidOption, exit 1flutter emulators --launch ID --coldinstall --bogus-flag,doctor --bogus-flag(also prefixes such asinstall --dev ID,doctor --fi)new my_app --bogus-flagmy_appcreatednew -x(a flag where the name goes; alsocreate)-x, exit 0--version -v,-v --verbose,version --anythingversion extrastill prints the version)install -d/install --device=with no valueinstall --device=emulator-5554build --release apk(any flag before the target)build apk --releasebuild --flavor web apk(two target names after a flag)build --release/build --release -- apk(no target before--),build --flavor prod(no target),rake ruflet:build[--help]run/update/debug/emulators --help,-hrake ruflet:update[--help],[-h]build --help,-hnew/create [NAME] -h/--help(new --help,new my_app -h,create my_app --help)--help, ormy_app), exit 0install --help,doctor --help(and-h)version --help,-v -hhelp <command word>(help build,--help build,help -v)help --boguscommand_run/command_debug/command_emulatorswith-hexit(SystemExit 0; emulators looked up Flutter first)command_build(%w[--flavor web apk]),command_emulators(%w[--cold])InvalidOptionProof (head
d8a08955, Ruby 4.0.5 unless noted)ruby test/compat/compat.rb --jobs 4: checked 309 goldens, exit 0.ruby -Ilib -Itest test/compat_goldens_test.rb: 317 runs, 702 assertions, 0 failures, 0 errors.64ea22d3adds 9 H1 entries (rake ruflet:update[--help],[-h],rake ruflet:build[--help],new my_app -h,create my_app --help,new -x,help -,build --self - apk,run main.rb -- --help). Their goldens were generated on maina9b58473, and a full--regeneratethere changed no other golden. Of its unit tests, 4 fail on the previous head's lib: the two direct-call tests, the new bare--build test and the build-target table with its new-rows. The fix commit97beb94cregenerates 6 of the 9 goldens, all listed above;help -,build --self - apkandrun main.rb -- --helpare unchanged frommain.43f75822's lib (and witha9b58473's), exactly 42 of the 309 fail: the 32 changed goldens and the 10 added ones that record new behavior. The other 9 added goldens pass onmain.97beb94c) each failcli_usage_test: the three review gaps, removing each handler's rescue, the two-checks in build, swappingreport_stop's branches, and a handler that turns OptionParser errors into usage errors. Removing update's rescue also fails the two rake H1 goldens.compat.rb docs-checkagainst ruflet_site main7ca19e6: 87 documented, 84 covered. The 3 forms the coverage table does not list yet areruflet run --web,build android --fullandbuild ipa --full. Their goldens generated on main43f75822pass unchanged on this head (run through the harness, not committed).packages/ruflet, one process per test file: 21 files, 378 runs, 0 failures, 0 errors. Ruby 3.4.5 (CI's): 21 files, 378 runs, 0 failures, 0 errors.cli_usage_test,cli_commands_test,cli_dispatch_test,cli_command_test,extra_command_test,run_command_testandupdate_command_testpass, one run each.packages/rufletchanges; ruflet_core, ruflet_server, ruflet_rails, the runtime, the template and the engine are untouched. Gem source grows by 15,001 bytes (packages/ruflet/lib357,021 to 372,022).Not in this PR
ruflet run --device IDrunning the app's own client on a device: CLI-01 (WP-06).debugrow ofruflet helpstill reads[scriptname|path]and there is no "runruflet help <command>" hint: both would change the documentedruflet helpoutput.ruflet help debugshows the right synopsis.buildexits 1, not 64, when Flutter rejects a forwarded flag; ruflet cannot know Flutter's flags.rake ruflet:update[--bogus-flag]still aborts with OptionParser'sInvalidOption(exit 1), as onmain(same golden on both, run through the harness, not committed): direct callers get OptionParser's errors unchanged.cli_reference.md:ruflet help <command>,--cold,install --device=ID, exit 64) are a follow-up docs PR.