GeezerVison is showing github.com — Documentation: mention required=True for options · Issue #514 · pallets/click
Documentation: mention required=True for options #514Labels docsUpdates to documentation, readme, docstrings, typos DescriptionThis is never mentioned as a possibility for click.option anywhere in the docs as far as I can tell (or at least it should be more prominent, maybe a section). (it talks about it in click.argument, but its unclear that it exists for both)
Someone just came to me saying, "we have to stop using click, i checked everywhere in their documentation, they don't support required options, which is important!"
Thanks :) Reacted by Stephen Rosen, Eyal Levin, Mike Nerone, Christian Hotz-Behofsits, keisar, marthjod, Hugh Saunders, Morris Alper, Sam Mingo, NAKATA Keisuke and 29 more Activitychanged the title [-]Documentation: mention required=True[/-] [+]Documentation: mention required=True for options[/+] on Feb 4, 2016rsiemens commented on Feb 5, 2016 I think its intentional that it is not mentioned. Per the doc here
As its name indicates, an option is optional. While arguments can be optional within reason, they are much more restricted in how optional they can be.
While you can have required options, the nature of an option is that it is not required. Perhaps using the default=value would be better. pmdarrow commented on Feb 5, 2016 @nudies by why provide the option if it's not intended to be used? IMO it should be removed from the public API or documented. Reacted by Ales Zoulek and Gui Talarico gibiansky commented on Feb 8, 2016 I don't know if this is an intended usecase, or maybe we are misusing click, but for us, all our command line parameters are options. Arguments do not provide the --name syntax, and for our CLIs we want every single thing to be prefixed with --what-it-is, in the style of keyword arguments in Python. As a result we use click.option almost exclusively, except for when we need nargs=-1; but that means that we need required=True sometimes for click.option.
Please don't remove remove this functionality; we would be very sad if our use case were deprecated for purely aesthetic reasons Reacted by Eyal Levin, Mike Nerone, dseisun-stripe, Sam Mingo, M, Ales Zoulek, Jason Nader, Dmitry Kartsev, Nimish Telang, Laurent Direr and 23 more pmdarrow commented on Feb 8, 2016 I should have mentioned I'm in favour of documenting & supporting it as well, not removing it (I realize it didn't sound like that from my comment). Reacted by Sam Mingo and Tamás Szelei ariscn commented on Mar 22, 2016 Big +1 for all the reasons stated. Options are self-documenting (--my-whatever foo), and are sometimes (often!) required. Reacted by Sam Mingo, Ales Zoulek, Benjamin and Justin Poehnelt fleipold commented on Sep 13, 2016 I have also switched to using named options as named arguments. This seems to be a widely used practice. Reacted by Peter Darrow, Stephen Rosen, Eyal Levin, Mike Nerone and Sam Mingo rr326 commented on Jan 10, 2017 +1 as well. I KNEW there must be a "required" field - and this issue is where I found the documentation! Reacted by Mikko Ohtamaa, Sam Mingo, Craig Patten, Seth Porter, Sam Partington and Zander marcinpraczko commented on Apr 7, 2017 +1 to document this - still seems be not documented.
And in multiple arguments having required option is happening more quite often. For example writing something for search (as I am doing now).
So need following syntax:
app command --search 'string'
# --search is required at this moment
So I would ask for updating documentation as well. Reacted by Sam Mingo, outime, howdydoody123, Dmitry Kartsev and kevgliss davidvhill commented on Jul 20, 2017 +1 Named in lieu of positional parameters are pretty important for us to help prevent coding errors. In our case the named parameters are not optional. burakalver commented on Apr 8, 2018 also useful for "if option a is provided than option b is required"; otherwise b is optional. gibiansky commented on May 18, 2018 Two years later I am delighted :) Thank you! (For fixing the issue and for an awesome library I've been using for years now!) Reacted by Tamás Szelei, Oskar Weser, scgbckbone, Brian Donaldson, Alexander Elvers and Krassimir Valev locked as resolved and limited conversation to collaborators on Jul 17, 2018
MetadataMetadatadocsUpdates to documentation, readme, docstrings, typos DevelopmentNo branches or pull requestsIssue actions
|