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

Allow showing default values globally. #1018

Closed
mchwalisz opened this issue May 17, 2018 · 14 comments
Closed

Allow showing default values globally. #1018

mchwalisz opened this issue May 17, 2018 · 14 comments

Comments

@mchwalisz
Copy link

Feature request, as in #646, we already had a discussion how to easily show default values for options. As context_settings is already used to configure global settings anyway, the idea would be to allow the following:

@click.command(
    help='Command helptext',
    context_settings=dict(show_default=True))
@click.option("--test", default="foobar", help="Option helptext")
def cli(test):
    pass

Which should enable show_default for all options and give the following help text:

$ cli --help
Usage: cli [OPTIONS]

  Command helptext

Options:
  --test TEXT   Option helptext. Default: 'foobar'
  --help        Show this message and exit.
@mchwalisz
Copy link
Author

If implemented correctly (haven't looked into the code). It should also work for @click.group()

@lukeyeager
Copy link

lukeyeager commented Aug 29, 2018

Temporary workaround:

import functools
import click

# Use this instead of click.option
click_option = functools.partial(click.option, show_default=True)

@click.command()
@click_option('--name', default='Luke')
def say_hi(name):
    print(name)

if __name__ == '__main__':
    say_hi()

@drorata
Copy link

drorata commented Sep 26, 2018

Thanks @lukeyeager for the nice idea.

Is this enhancement aligns with the package's developers agenda?

@jcrotts
Copy link
Member

jcrotts commented May 23, 2019

This seems to be fixed in #1225 .

@jcrotts jcrotts closed this as completed May 23, 2019
@drorata
Copy link

drorata commented Aug 26, 2019

The merged #1225 is not yet part of version 7.0, is that right? When is it planned to be released?

@jcrotts
Copy link
Member

jcrotts commented Aug 26, 2019

It should be in the 7.x branch. https://github.com/pallets/click/tree/7.x

Not released on PyPi yet, but you can checkout the 7.x branch and install it with the setup.py if you need this change.

@ehles
Copy link

ehles commented Sep 23, 2019

we have a lot of cli commands and a huge more params for them and going to show default, so we very appreciate for releasing this feature.
anyway a year has passed since release 7.0, do you have any plans for releasing 7.1?
Thanks.

@pohmelie
Copy link

pohmelie commented Jan 24, 2020

Spent some time to dig this. It confusing that documentation promotes this feature, but it is actually not there.

@altendky
Copy link
Contributor

The lack of a latest selection for version, or any actual releases, is a bit odd.

image

@davidism
Copy link
Member

davidism commented Jan 24, 2020

Just like git, "master" contains the latest development code, and "7.x" contains the latest 7.x branch code. I'm not sure what's odd about that. If something doesn't have a .. versionchanged:: marker and you think it should, please make a PR.

@altendky
Copy link
Contributor

altendky commented Jan 24, 2020

http://www.attrs.org/en/stable/

image

I may have incorrectly referred to lacking 'latest'. So I think the click 'master' is what others often refer to in this context as 'latest'. They also then have 'stable' which... I think is the most recent release? Then they have the actual releases rather than just development branches. If click offered 7.0 rather than just 7.x docs then people running 7.0 could see the docs for their actual version they are running rather than a preview of features they do not yet have access to via released versions on PyPI.

@altendky
Copy link
Contributor

Though yes, this change does also seem to have been missing the versionadded note.

@pohmelie
Copy link

But this change did not added to any version yet. Latest version is 7.0 and it lacks of this feature.

@altendky
Copy link
Contributor

@pohmelie, correct. So I set the version added to 7.1 in the PR. I think some projects have you put a marker in and then they have a tool that autofills the proper version when making a release. My quick look around Click didn't show that. But, if I missed it, whoever reviews the PR will hopefully catch it and teach me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants