darrenburns / ward

Ward is a modern test framework for Python with a focus on productivity and readability.
https://ward.readthedocs.io
MIT License
1.21k stars 53 forks source link

Food for thought regarding click #118

Closed thebigmunch closed 4 years ago

thebigmunch commented 4 years ago

I've been programming in Python for nearly 2 decades. For almost as long as that, I've been searching for something better than what the stdlib provided. In that search, I've tried out most Python CLI packages large and small. Yet I always ended up back at optparse and now argparse.

That not to say I'm evangelical one way or another; I always end up using what works best for me. Take two of my projects as examples: google-music-scripts and thorod. Both of them started out using docopt. When that became hard to maintain/didn't support something I needed, I siwtched them to click. Eventually that became hard to maintain/didn't support something I needed. So back to argparse. In fact, I was able to split out a good portion of the CLI stuff into my utility package for reusability. Now I don't have to copy/paste and test the code in every CLI app I make.

The warts of click start showing even with relatively small, simple scripts. And they come to a head once you reach a CLI of moderate size/complexity. Some of the issues I've run into:

There are more that I've run into involving subcommands that may not be applicable to ward. And I'm sure there's plenty I've forgotten. There are definitely some articles out there expressing these and more.

Just wanted to share my experiences from similar situations in case it strikes a chord.

** Example output of one of google-music-script's commands:

$ gms up -h
Usage: gms upload [OPTIONS] [INCLUDE_PATH]...

Upload song(s) to Google Music.

Options:
  -h, --help            Display help.
  -V, --version         Output version.

Action:
  -n, --dry-run         Output results without taking action.

Logging:
  -v, --verbose         Increase verbosity of output.
  -q, --quiet           Decrease verbosity of output.
  --debug               Output log messages from dependencies.
  --log-to-stdout       Log to stdout.
  --no-log-to-stdout    Don't log to stdout.
  --log-to-file         Log to file.
  --no-log-to-file      Don't log to file.

Identification:
  -u USER, --username USER
                        Your Google username or e-mail address.
                        Used to separate saved credentials.
  --uploader-id ID      A unique id given as a MAC address (e.g. '00:11:22:33:AA:BB').
                        This should only be provided when the default does not work.
  --device-id ID        A mobile device id.

Local:
  --no-recursion        Disable recursion when scanning for local files.
                        Recursion is enabled by default.
  --max-depth DEPTH     Set maximum depth of recursion when scanning for local files.
                        Default is infinite recursion.
  -xp PATH, --exclude-path PATH
                        Exclude filepaths.
                        Can be specified multiple times.
  -xr RX, --exclude-regex RX
                        Exclude filepaths using regular expressions.
                        Can be specified multiple times.
  -xg GP, --exclude-glob GP
                        Exclude filepaths using glob patterns.
                        Can be specified multiple times.
                        Absolute glob patterns not supported.

Filter:
  -f FILTER, --filter FILTER
                        Metadata filters.
                        Can be specified multiple times.
  --created-in DATE     Include items created in year or year/month.
  --created-on DATE     Include items created on date.
  --created-before DATE
                        Include items created before datetime.
  --created-after DATE  Include items created after datetime.
  --modified-in DATE    Include items created in year or year/month.
  --modified-on DATE    Include items created on date.
  --modified-before DATE
                        Include items modified before datetime.
  --modified-after DATE
                        Include items modified after datetime.

Misc:
  --delete-on-success   Delete successfully uploaded local files.
  --no-sample           Don't create audio sample with ffmpeg/avconv.
                        Send empty audio sample.
  --album-art ART_PATHS
                        Comma-separated list of album art filepaths.
                        Can be relative filenames and/or absolute filepaths.

Sync:
  --use-hash            Use audio hash to sync songs.
  --no-use-hash         Don't use audio hash to sync songs.
  --use-metadata        Use metadata to sync songs.
  --no-use-metadata     Don't use metadata to sync songs.

Include:
  PATH                  Local paths to include songs from.
darrenburns commented 4 years ago

Thanks for this. I have been having some issues with Click recently that have made me question how much I'm gaining from using it. I'm repeatedly asking myself the question "how do I make this work the Click way?"

I'm using argparse in another project and finding it a little easier to work with so far. As I continue to use the two I may hit a point where I consider migrating 😄