Giter Site home page Giter Site logo

Allow to override options about click HOT 8 CLOSED

pallets avatar pallets commented on July 23, 2024
Allow to override options

from click.

Comments (8)

douglarek avatar douglarek commented on July 23, 2024

@untitaker IMO, maybe Click does not have alias idea. But If we can use -l why we use --list ?

And if you have used argparse, you know --help in @click.option('-h', '--help', is_flag=True, ...) is equal to dest in argparse;

As the issue you mentioned above, you can handle ctx.format_help() with str operation very easily:

def print_help(ctx, value):
    if not value:
        return
    lines = ctx.format_help().replace('-h', '--help/-h')
    print '\n'.join(lines.split('\n')[:-1])
    ctx.exit()

Hope this will help!

from click.

mitsuhiko avatar mitsuhiko commented on July 23, 2024

You can remove the default help option through a parameter already. I don't think this feature is necessary.

from click.

zspencer avatar zspencer commented on July 23, 2024

the parameter @mitsuhiko is referencing is the add_help_option which is passed to @click.group (and similar decorators) like so: @click.group(add_help_option=False)

from click.

untitaker avatar untitaker commented on July 23, 2024

I don't want to remove the help option, i want to create an alias for it. I currently don't think writing around 20 lines of code to remove the help option and add it again (this time with an alias) is very convenient.

from click.

zspencer avatar zspencer commented on July 23, 2024

untitaker, the following is a snippet that aliases --help to --wtf:

@click.group(add_help_option=False)
@click.help_option('-w', '--wtf')
def command_a():
  pass

Unfortunately, it doesn't seem sub-commands inherit this behavior; so if you have a subcommand you have to do:

@command_a.command(add_help_option=False)
@click.help_option('-w', '--wtf')
def subcommand():
  pass

So if you have 10 commands you do have to add 20 lines of code :(. I'm sure there's a better way, perhaps by creating a custom command class that inherits from the base command and have it do this automatically; but I haven't dug into the code enough to figure that out.

from click.

mitsuhiko avatar mitsuhiko commented on July 23, 2024

I can see this being annoying. Contemplating special casing help here.

from click.

untitaker avatar untitaker commented on July 23, 2024

Maybe we could fix this particular "stage" of the problem:

However, click then doesn't recognize -h as an alias for --help and shows
this ugly help output for those options:

-h      Show this message and exit.
--help  Show this message and exit.

And make click recognize two options to be the same when the function names are the same.

from click.

mitsuhiko avatar mitsuhiko commented on July 23, 2024

I implemented this through a completely different system now. You can do this now:

DEFAULTS = dict(help_option_names=['-h', '--help'])

@click.command(context_defaults=DEFAULTS)
def cli():
    pass

All commands below that command will then have -h and --help as help options. In case of a conflict the conflicting value is removed.

from click.

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.