-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate CLI parsing to click library #237
base: master
Are you sure you want to change the base?
Migrate CLI parsing to click library #237
Conversation
Complete overhaul of top-level parsing. Delegation to subcommands using click.group(). Structure of parsing within each of the subcommand is retained, but some of the wrapping code for help functions and version options is no longer needed. Changes to CLI API: - webdav/archive/mirror flags no longer specifiable as mutually exclusive group - argument order in comment is changed to smt comment COMMENT [LABEL] The first of these cannot be fixed without changes to click API (see issue open-research#257 pallets/click#257). The second is a little more annoying from a user perspective. Though it may be fixable given current api. So far, though, I can't figure out how to pass optional arguments before required. I wouldn't be surprised if it isn't possible either. A few associated changes: * Currently using click to print in simplest way possible: click echo, * and for error-like messages specifying err=True to print to standard error. * Because of change, help files look and print slightly (or in some cases majorly) differently Changes to commands.py API: * Breaking changes to the arguments expected by all functions implementing smt subcommands. This is unavoidable with click. Remaining issues : * many test failures due to API changes -- around 67 (filtering calls to parse_arguments from grep -E 'commands\..+(\(|\,)' test_commands.py) lines of the test suite for commands.py will need to be rewritten * test rewrite should be straightforward change from tuples to named args * migration to click doesn't intend to change downstream behavior so passing tests can serve as a check on rewrite * docs not updated to modified look of help pages
For the first, it seems this can be supported by adding our own check that only one of the options has been chosen; it's just that click will not auto-generate an appropriate help message. The second (which also applies to
I think this is ok. The commands.py API is not really intended to be used directly. |
One feature I'd like to add to Sumatra is being able to run "smt" with no arguments, as an equivalent to "smt run" but with arguments that get passed straight to the process, e.g.
as an alternative to
Will click handle this case, or must there always be a subcommand? |
Good suggestion on the exclusive group issue. I need to dig into the other issue further. For the second feature you mention, a crude approach would be to add wrappers for each executable name as subcommands that call run under the hood. It might be better to just dispatch unknown subcommands to our own parsing command though. In sum, I'll look into these:
|
Looking at the second issue, it seems I'd advocate for switching the argument order in |
The unknown command dispatch seems possible: http://click.pocoo.org/4/commands/#group-invocation-without-command @apdavison thoughts on the course I suggested in last comment? Specifically:
|
Unfortunately, this seems to be just "no command", not "unknown command". I tried with a toy script, and giving unknown arguments produces an error. However, having dug into the
On reflection, I agree this is a good idea. |
Oops thanks for checking. I'll open the unknown command as a separate enhancement issue and work on tests for this I may wait for py3 stuff to stabilize and rebase onto it. Sound good? - Jaime On Tue, Jun 2, 2015 at 12:27 PM, Andrew Davison notifications@github.com
|
Yes, sounds like a good plan. |
ok, the py3 stuff is merged. You should be ok to rebase this onto master. |
This is a large PR, but would fix #234 . If maintainers agree this is a good direction, some additional work is needed:
commands.py
Complete overhaul of top-level parsing. Delegation to subcommands using
click.group(). Structure of parsing within each of the subcommand is
retained, but some of the wrapping code for help functions and version
options is no longer needed.
Changes to CLI API:
exclusive group
The first of these cannot be fixed without changes to click API (see
issue #257 at click pallets/click#257). The second is
a little more annoying from a user perspective. Though it may be fixable
given current api. So far, though, I can't figure out how to pass
optional arguments before required. I wouldn't be surprised if it isn't
possible either.
A few associated changes:
error-like messages specifying err=True to print to standard error.
cases majorly) differently
Changes to commands.py API:
implementing smt subcommands. This is unavoidable with click.
Remaining issues :
(filtering calls to parse_arguments from grep -E 'commands..+((|,)'
test_commands.py) lines of the test suite for commands.py will need to
be rewritten
passing tests can serve as a check on rewrite