Giter Site home page Giter Site logo

Comments (3)

wkhere avatar wkhere commented on August 16, 2024

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.

jawher avatar jawher commented on August 16, 2024

@wkhere Thank you for your suggestions !

Could you clarify a bit the following points ?

  • argparse's metavar: just a string, e.g. bool or true|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.

wkhere avatar wkhere commented on August 16, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.