Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support shorter flag syntax #56

Open
brandonkal opened this issue Mar 20, 2020 · 4 comments
Open

Support shorter flag syntax #56

brandonkal opened this issue Mar 20, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@brandonkal
Copy link

brandonkal commented Mar 20, 2020

Currently adding a flag is quite verbose:

## purchase (price)

> Calculate the total price of something.

**OPTIONS**
* tax
    * flags: -t --tax
    * type: number
    * desc: What's the tax?

~~~sh
TAX=${tax:-1} # Fallback to 1 if not supplied
echo "Total: $(($price * $TAX))"
~~~

We end needing to write out the flag name twice and use 4 lines.
I'd like to propose support for a shorter readable syntax:

## purchase (price)

> Calculate the total price of something.

**OPTIONS**
* flags: -t --tax |number| What's the tax?

~~~sh
TAX=${tax:-1} # Fallback to 1 if not supplied
echo "Total: $(($price * $TAX))"
~~~

If no type is specified, the |number| part can be omitted.

@brandonkal
Copy link
Author

This also has the benefit of looking closer to the output of the CLI help where flag and description are printed on the same line.

@MggMuggins
Copy link

Might I suggest flag instead of flags, since each line defines a flag and it will be repeated many times? Ex:

## purchase (price)

> Calculate the total price of something.

**OPTIONS**
* flag: -t --tax |number| What's the tax?
* flag: ...

~~~sh
TAX=${tax:-1} # Fallback to 1 if not supplied
echo "Total: $(($price * $TAX))"
~~~

@jacobdeichert jacobdeichert added the enhancement New feature or request label Mar 31, 2020
@slavaGanzin
Copy link

slavaGanzin commented Nov 10, 2022

And default value as well can go into square braces like:

flag: -t --tax |number| [-1] What's the tax?

@dswd
Copy link

dswd commented Aug 17, 2023

+1 for shorter options strings

How about the DocOpt syntax? There is even a Rust implementation that you could take code from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants