pyupio / safety

Safety checks Python dependencies for known security vulnerabilities and suggests the proper remediations for vulnerabilities detected.
https://safetycli.com/product/safety-cli
MIT License
1.66k stars 141 forks source link

support shell globs with a new command that takes multiple file options #306

Open graingert opened 4 years ago

graingert commented 4 years ago

Description

I'm trying to run safety check -r **/requirements*.txt but -r only allows one command

introduce a new command that supports unixy [FILE...] safety check_requirements [OPTION...] [FILE...]

lf1up commented 4 years ago

@graingert thank you for this case. You are right, at this moment -r allows only one file per option. You need to use -r option multiple times if you want to pass more files (https://click.palletsprojects.com/en/7.x/options/#multiple-options). There is no [FILE...] support due to the click library limitations (we are using this library to parse command line args: https://github.com/pallets/click/issues/484). I added this to our list of upcoming features and bugfixes.

Meanwhile, you can try with this quick workaround: for f in **/requirements*.txt; do safety check -r "$f"; done

graingert commented 4 years ago

@lf1up https://click.palletsprojects.com/en/7.x/arguments/#variadic-arguments it looks like you can pass nargs=-1 now

lf1up commented 4 years ago

@graingert at this moment we are using @click.option almost everywhere. Possible usage of @click.argument should be considered and tested, because it is not an equivalent (drop-in) replacement.

filonik commented 1 year ago

Just wanted to echo the desire to support variadic options. My use case also involves using shell globs/wildcards within options. I think the OptionEatAll solution on StackOverflow gets the expected behavior right:

https://stackoverflow.com/questions/48391777/nargs-equivalent-for-options-in-click

Although this is a workable solution, it would be nice to have it supported in the library directly. It feels like quite a natural feature, especially considering variadic arguments.