pallets / click

Python composable command line interface toolkit
https://click.palletsprojects.com
BSD 3-Clause "New" or "Revised" License
15.76k stars 1.4k forks source link

Add version option names #1731

Closed tyki6 closed 3 years ago

tyki6 commented 3 years ago

Hi,

How can i set specific version option name like ['-V', '---version'] like help_option_names? Regards,

my code:

import click

from rawsec_cli.cli.command.listCommand import listCommand
from rawsec_cli.cli.command.searchCommand import search
from rawsec_cli.cli.command.submitCommand import submit
from rawsec_cli.tools import loadInventoryJson
from rawsec_cli import __version__, __commit__

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

@click.version_option(__version__, message=f'%(prog)s, version %(version)s, commit {__commit__}\nFull documentation is at https://rawsec-cli.readthedocs.io/')
@click.group(context_settings=CONTEXT_SETTINGS)
@click.pass_context
def cli(ctx):
    """
    Rawsec's Cybersecurity Inventory is an inventory with 4 category(Tools, Resources, Ctf Platforms, OS).\n
    This cli can search a project,list all projects by category, you can filter your research with option --help for more information.\n
    full documentation: https://rawsec-cli.readthedocs.io/
    \f
    :param ctx: click context
    :return:
    """
    ctx.ensure_object(dict)
    ctx.obj["json"] = loadInventoryJson()

cli.add_command(search)
cli.add_command(listCommand)
cli.add_command(submit)

if __name__ == "__main__":
    cli(obj={})

Now:

rawsec-cli --help
Options:
  --version   Show the version and exit.
  -h, --help  Show this message and exit.

Expected:

rawsec-cli --help
Options:
  **-V**,--version   Show the version and exit.
  -h, --help  Show this message and exit.
davidism commented 3 years ago

Same as any other option: @version_option("-V", "--version")