Comments (3)
Alternative to back quotes would be also to add Metavar to the *Opt structs, acting similar as in Python's argparse.
Yet another alternative would be reusing names from Spec in this -h output.
That would be actually super helpful, as mow.cli
is already more advanced than most of cli parsers, this one area seems to ask for improvement.
from mow.cli.
@wkhere Thank you for your suggestions !
Could you clarify a bit the following points ?
- argparse's metavar: just a string, e.g.
bool
ortrue|false
which when help is printed would render as:-n (bool) No-op mode.
? - reusing names from Spec: not sure I understood this one
from mow.cli.
@jawher thank you for a swift reply!
Metavar
Metavar is a concrete name representing flag value (or arg value). In pythonic argparse it is displayed in usage headline (well, we seem to have Spec for that) and in usage lines describing each option.
Following an example from the original doc:
>>> parser.add_argument('--foo', metavar='YYY')
>>> parser.add_argument('bar', metavar='XXX')
>>> parser.parse_args('X --foo Y'.split())
Namespace(bar='X', foo='Y')
>>> parser.print_help()
usage: [-h] [--foo YYY] XXX
positional arguments:
XXX
optional arguments:
-h, --help show this help message and exit
--foo YYY
Hope this example explains.
PS. I specifically referred to Python's argparse a it became de facto standard in Python world, included in Py3 and backported to Py2, and lot of people coming from that background know it.
Here, I think, we could define Metavar in Opt struct, defaulting to Opt type (so it would give bool
in your example), and print it in usage text.
In Go world this has been a bit different, flag
has the mechanism that if you use back quotes in option's description then it is also used like metavar above - see the doc.
Several other projects incl. pflag
/cobra
copied that behaviour.
Spec
By reusing names from Spec I meant,
if an option requires value and we're writing the Spec, then we must refer this value somehow, ie. -x=<foo>
.
Then we could print this also in options details instead of just -x
+ description.
I am sorry for somewhat chaotic style of writing, in a hurry a bit, hope this is little clearer.
[EDIT: changed formatting a bit]
from mow.cli.
Related Issues (20)
- Display missing required params
- Expose a model of the command structure HOT 6
- StringsOpt can not start with dashes HOT 12
- Custom exiter
- Implement out-of-the-box support for shell autocompletion (source code available!)
- Possible bug with option specs HOT 2
- Extension: check docker containerized starter with mow.cli as default
- Example of writing test HOT 1
- Global StringArg + command: contextual help does not work HOT 4
- Wrapping long spec strings
- Extension: Quick start template HOT 1
- BoolsOpt() for repeated flags (Boolean options)? HOT 1
- Spec is not inferred correctly for multi-value argument
- Please make a release that includes the go.mod file HOT 3
- Inter-option ordering HOT 3
- Provide a way to mark options as un-ordered HOT 1
- Associate option values with specific arguments
- Cannot use exclusive choices with OPTIONS
- The default value of the empty default option is not printed correctly HOT 1
- Add support to make a command hidden in cli
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mow.cli.