feat: give InputRedirect a command-line interface - #11
Merged
Conversation
Starting the tool from a shortcut or a script had no way to switch a redirect on: the only path was the interactive menu, which needs a person at the keyboard. This adds --mouse and --keyboard so the redirect that is wanted can be named up front. With either flag the program starts as usual, switches on exactly what was asked for, and prints one green line saying what is running instead of drawing the menu. Both flags together turn on both. Closing the window or pressing Ctrl+C still switches everything back and ends the program, on the same console control handler the menu already relies on, so the flag mode needs no teardown of its own. An unrecognised argument is refused with its own message and exit code rather than silently opening the menu, so a misspelt flag cannot look like it did nothing.
The first commit rewrote the whole of app/mod.rs and, in doing so, dropped shut_down, the Default and Drop impls, and rebuilt the dashboard against driver methods that do not exist. Restore the original file verbatim and keep only the three intended additions: the cli module, the command-line branch in run, and run_headless.
Many command-line tools take a short spelling of every long flag and a --help that lists them, and people reach for both by habit. Without them -m or -h just fell into the "unknown argument" path, which is a confusing way to greet someone typing what they expect to work. -m and -k are now accepted as exact synonyms for --mouse and --keyboard, and --help / -h prints the list of flags and exits. Help is answered before the console is prepared, the single-instance lock is taken or the driver is touched, so it is plain text and costs nothing; it wins over a redirect given on the same line, since someone reading the flags did not mean to start one. wait_before_the_window_closes keeps the text on screen for a double-click launch and returns at once from a shell. parse now returns a Request enum (Menu / Redirect / Help) rather than a bare Requested, so "show the menu", "run these redirects" and "print help" are distinct outcomes the caller matches on instead of inferring.
Help was pausing on "Press any key to close this window", which is menu behaviour: a command-line tool asked for its usage prints it and returns at once. The pause only made sense for a startup error a double-click user would otherwise never see; help is something they typed, so it just prints and the program leaves.
The line describing what --mouse and --keyboard do to the menu repeated what the options table already says. Help stays to the point: what the flags are, and how the program ends.
In flag mode the line naming what is running sat flush against the setup lines that scrolled past, so the one line worth reading did not stand out. A blank line before it gives it room, the same way the menu spaces its blocks. The --help entry said "show this help and exit"; that a command-line tool returns after printing its usage is a given, so the entry is just "show this help".
The driver-removal action was called "remove" everywhere in the code and the README, but the menu key was D, the odd one out. This settles on "remove": the menu key is now R, and a matching -r / --remove-driver flag runs the very same flow from the command line - it confirms, removes the driver package and offers the restart, then ends. Help lists the new flag, README gains a Command line section describing all of them, and the Quick Start key table shows R.
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.
Why
Starting the tool from a shortcut, a scheduled task, or a script had no way to say what you wanted - the only path was the interactive menu, which needs a person at the keyboard. This gives InputRedirect a small command-line interface so the common cases can be named up front.
What
Redirect flags
-m,--mouse- start as usual and switch the mouse redirect on-k,--keyboard- start as usual and switch the keyboard redirect onMouse redirect activeKeyboard redirect activeMouse and keyboard redirect activeexit::watch_for_closealready installs, which switches the redirects back and ends the process - the exact same teardown the menu relies on.Remove the driver
-r,--remove-driver- confirms, removes the installed driver package, and offers the restart, then ends.InputRedirect: no driver is installed, so there is nothing to remove.and exits without callingDriver::connect, so a removal request can never install the driver it was asked to remove.Nothing was removeddirectly before the CLI session ends; it is not left waiting for a menu redraw that never happens.R(wasD), so the key, the flag and the wording ("remove") all line up.Help
-h,--help- prints the usage and exits at once. No "press any key": help is something you typed, not a startup message a double-click user would otherwise miss.Errors
Error::Usageand exit code5, rather than silently opening the menu, so a misspelt flag cannot look like it did nothing.InputRedirect --help, keeping the guidance complete as options are added.When more than one thing is asked for, the request that undoes the most wins, so nothing is half-done and then thrown away:
--helpfirst, then--remove-driver, then the redirects. With no arguments the behaviour is unchanged: the interactive menu opens as before.Files
src/app/cli.rs(new) - parses the arguments into aRequest(Menu,Redirect(Requested),RemoveDriver,Help) and produces the one status line the flag mode prints.src/app/mod.rs-runparses the command line first;--helpanswers before anything is claimed,--remove-driverchecks for an installed package before startup and reports both no-op outcomes directly, and a redirect hands off torun_headless.src/main.rs- usage errors point to--helprather than carrying a partial hard-coded flag list.src/ui/prompt.rs- the remove-driver menu key moves fromdtor.src/ui/screen.rs- the menu row showsR.README.md- new Command line section with the usage/options block, and the Quick Start key table now showsR.Tests
src/app/cli.rsunit tests cover: no arguments (menu), each flag alone (long and short), both redirects together, order independence, a repeated flag,--helpand--remove-drivereach winning over a redirect alongside them,--helpwinning over--remove-driver, an unknown argument (alone and after a valid one), and each redirect combination mapping to the right status line.src/ui/prompt.rstests are updated for theRscan code.Verification
The Windows CI runs
cargo fmt --all --check,cargo clippy --locked --all-targets -- -D warnings,cargo test --locked --all-targets, andcargo build --locked --release; the dependency audit runs separately. No dependencies were added, soCargo.lockis unchanged.