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

Let user specify default/fallback value for named flags #59

Open
ogata-k opened this issue Apr 25, 2020 · 8 comments
Open

Let user specify default/fallback value for named flags #59

ogata-k opened this issue Apr 25, 2020 · 8 comments
Labels
enhancement New feature or request

Comments

@ogata-k
Copy link

ogata-k commented Apr 25, 2020

I want to specify parameters list and default for option.

For instance.
When make command "formatter" from csv to json or tsv, with default no-convert,I want to specify following:

## formatter
**OPTIONS**
* target
    * flags: -t --target
    * type: string
    * desc: Which port to serve on
    * list: csv, json, tsv
    * default: csv
@jacobdeichert jacobdeichert added the enhancement New feature or request label Apr 25, 2020
@brandonkal
Copy link

A flag doesn't make sense with a default.

@cherusk
Copy link
Contributor

cherusk commented May 31, 2020

I agree with @ogata-k . I'd even extend this to more complex types (e.g. dicts) and phasing in defaulting for both categories, optional/positional parameters. In line with what py argparse [1] does. argparse could be inspiration for more features I sense.

[1] https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.add_argument

@jacobdeichert
Copy link
Owner

A default: something flag value is easy to support.

As a workaround for now, in my readme example I used a bash fallback value like this:

PORT=${port:-8080} # Set a fallback port if flag is not supplied

So whatever scripting language you're using, you can easily check if the flag is unset and use your fallback for now.

@ogata-k
Copy link
Author

ogata-k commented Jun 1, 2020

I think so too in now for default flag.

@cherusk
Copy link
Contributor

cherusk commented Jun 1, 2020 via email

@ogata-k ogata-k closed this as completed Dec 24, 2020
@chengxuncc
Copy link

chengxuncc commented Jan 18, 2021

So whatever scripting language you're using, you can easily check if the flag is unset and use your fallback for now.

A default value is convenient when you don't remember how to manipular environment variable with other languages, and some language like Java is hard to export environment.

@slavaGanzin
Copy link

Definitely +1 on this

It's a three line change, why even discuss this?

@jacobdeichert
Copy link
Owner

I'll reopen this since it does seem useful as a feature. Specifying a default value for a flag lets the user easily see what the fallback value is if they don't supply one.

It's a three line change, why even discuss this?

Just because it's a quick change (plus writing tests, documentation) doesn't automatically mean that it should be something we add. Opening an issue for proposing & discussing new features is preferred and it lets me gauge how much interest there is. In this case, there's definitely interest.

@jacobdeichert jacobdeichert reopened this Nov 11, 2022
@jacobdeichert jacobdeichert changed the title want option param: list, default Let user specify default/fallback value for named flags Nov 11, 2022
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

6 participants