Git Product home page Git Product logo

click-default-group's People

Contributors

geyang avatar jcollado avatar lowks avatar mjenczmyk avatar sublee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

click-default-group's Issues

Include LICENSE in PyPI tarball

This project uses the BSD 3-clause license, which requires that the license be distributed with all copies of the source code:

  Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

The PyPI source tarball does not include such a copy of the license:

> curl -fsSL 'https://files.pythonhosted.org/packages/source/c/click-default-group/click-default-group-1.2.2.tar.gz' | tar -tz
click-default-group-1.2.2/
click-default-group-1.2.2/PKG-INFO
click-default-group-1.2.2/README.md
click-default-group-1.2.2/click_default_group.egg-info/
click-default-group-1.2.2/click_default_group.egg-info/PKG-INFO
click-default-group-1.2.2/click_default_group.egg-info/SOURCES.txt
click-default-group-1.2.2/click_default_group.egg-info/dependency_links.txt
click-default-group-1.2.2/click_default_group.egg-info/requires.txt
click-default-group-1.2.2/click_default_group.egg-info/top_level.txt
click-default-group-1.2.2/click_default_group.py
click-default-group-1.2.2/setup.cfg
click-default-group-1.2.2/setup.py

That makes it difficult/impossible to legally include in third-party/OS package repositories, which require packaged code to be distributed in a license-compliant manner. It would be great if the PyPI tarball could be updated to include the license!

Deprecation during install with latest version of `pip`

When installing towncrier in Python 3.11 using pip 23.0.1, I got the warning:

DEPRECATION: click-default-group is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change.
A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559

This appears to be an issue with how click-default-group handles getting itself installed.

How to provide `--version` option?

Hi I'm looking for a way to use click-default-group while providing a cli --version option to get the cli version. Is there a way to get cli --version to print cli 0.0.1?

import click
from click_default_group import DefaultGroup

VERSION = 'cli 0.0.1'

@click.group(cls=DefaultGroup, default='foo', default_if_no_args=True)
@click.option('--version', is_flag=True, default=False)
def cli(version):
    click.echo(VERSION)

@cli.command()
def foo():
    click.echo('foo')

@cli.command()
def bar():
    click.echo('bar')


@cli.command('--version')
def cli_version():
    click.echo(VERSION)

cli()

$ python cli.py --version
Usage: cli.py [OPTIONS] COMMAND [ARGS]...

Error: Missing command.

conflict with other extensions like click-help-colors

Due to the use of custom class, I discovered that I cannot add the default group to a group that is already using it:

from click_help_colors import HelpColorsGroup, HelpColorsCommand

@click.group(
    cls=HelpColorsGroup,
    help_headers_color='yellow'
)

Is there a workaround for this?

click-default-group breaks click-repl

From pallets/click#430 (comment):

Using

@click.group(cls=DefaultGroup, default='shell', default_if_no_args=True)

breaks the auto-completion integration with prompt-toolkit from click-repl.

Why is it preferred versus the following anyway (which works, and does not break click-repl?

@click.group(invoke_without_command=True)
@click.option(
    '--profile',
    help='profile to use',
    default=u'default'
)
@click.pass_context
def cli(ctx, profile):
    ctx.obj = Config(_app, profile)
    if ctx.invoked_subcommand is None:
        ctx.invoke(cmd_shell)

Missing type hints causes mypy to complain

Because of the missing type hints, when using cls=DefaultGroupit is necessary to use # type: ignore to prevent errors like:

error: Untyped decorator makes function "my_function" untyped  [misc]

So I copied the types from click 8.1.7 which makes mypy happy. I'll open the PR shortly.

Missing command error when providing only group options

As title says, a missing command error is shown when only group options are passed to the prompt.

The expected behavior is that group options are handled by the group and then default command is invoked.

Minimum example

import click
from click_default_group import DefaultGroup

@click.group(cls=DefaultGroup, default='foo', default_if_no_args=True)
@click.option('-v', is_flag=True)
def cli(v):
    print('cli group exec')
    if v:
        print('Verbose!')

@cli.command()
@click.option('--config')
def foo(config):
    print('foo command exec')
    if config:
        print(f'config={config}')

Execution

$ program foo                           
--> normal call, works

$ program
--> default cmd is called, works

$ program --config=abc 
--> option is forwarded to 'foo' cmd, works

$ program -v --config=abc
--> '-v' option is parsed by group and '--config' is parsed by 'foo' cmd, works

$ program -v
--> doesn't work!

Default command name not used in help output

Let's say that I have a command with a default subcommand, when the default subcommand is implicity executed (i.e. subcommand was not typed), whatever value was used as argument is used as the subcommand name in the help string:

$ command does-not-exist -h
Usage: command does-not-exist [OPTIONS]

even if the subcommand wasn't passed, it should be part of the help string:

$ command does-not-exist -h
Usage: command subcommand [OPTIONS]

Include tests in PyPI source tarball

The source tarball distributed on PyPI does not include the tests:

> curl -fsSL 'https://files.pythonhosted.org/packages/source/c/click-default-group/click-default-group-1.2.2.tar.gz' | tar -tz
click-default-group-1.2.2/
click-default-group-1.2.2/PKG-INFO
click-default-group-1.2.2/README.md
click-default-group-1.2.2/click_default_group.egg-info/
click-default-group-1.2.2/click_default_group.egg-info/PKG-INFO
click-default-group-1.2.2/click_default_group.egg-info/SOURCES.txt
click-default-group-1.2.2/click_default_group.egg-info/dependency_links.txt
click-default-group-1.2.2/click_default_group.egg-info/requires.txt
click-default-group-1.2.2/click_default_group.egg-info/top_level.txt
click-default-group-1.2.2/click_default_group.py
click-default-group-1.2.2/setup.cfg
click-default-group-1.2.2/setup.py

It would be nice if it could do so, since that would enable OS-specific package repository hosts/builders to independently run tests & verify functionality/validity of these packages.

Customizing --help command for default groups

Is there a way I can redirect one of the subcommand --help output to the group command's --help?
For example:

@click.group(cls=DefaultGroup, default='foo', default_if_no_args=True)
def cli():
    pass

@cli.command()
def foo():
    click.echo('foo')

cli --help should output foo --help description.

Is this possible to customize --help in this way?

1.2.2: test suite is failing

+ /usr/bin/pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.10.0, pluggy-0.13.1
benchmark: 3.4.1 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
Using --randomly-seed=1090834362
rootdir: /home/tkloczko/rpmbuild/BUILD/click-default-group-1.2.2, configfile: setup.cfg
plugins: forked-1.3.0, shutil-1.7.0, virtualenv-1.7.0, expect-1.1.0, flake8-1.0.7, timeout-1.4.2, betamax-0.8.1, freezegun-0.4.2, aspectlib-1.5.2, toolbox-0.5, rerunfailures-9.1.1, requests-mock-1.9.3, cov-2.12.1, flaky-3.7.0, benchmark-3.4.1, xdist-2.3.0, pylama-7.7.1, datadir-1.3.1, regressions-2.2.0, cases-3.6.3, xprocess-0.18.1, black-0.3.12, anyio-3.3.0, asyncio-0.15.1, trio-0.7.0, subtests-0.5.0, isort-2.0.0, hypothesis-6.14.6, mock-3.6.1, profiling-1.7.0, randomly-3.8.0, Faker-8.12.1, nose2pytest-1.0.8, pyfakefs-4.5.1, tornado-0.8.1, twisted-1.13.3
collected 7 items

test.py ...F...                                                                                                                                                      [100%]

================================================================================= FAILURES =================================================================================
___________________________________________________________________ test_default_command_with_arguments ____________________________________________________________________

    def test_default_command_with_arguments():
        assert r.invoke(cli, ['--foo', 'foooo']).output == 'foooo\n'
>       assert 'no such option' in r.invoke(cli, ['-x']).output
E       assert 'no such option' in "Usage: cli foo [OPTIONS]\nTry 'cli foo --help' for help.\n\nError: No such option: -x\n"
E        +  where "Usage: cli foo [OPTIONS]\nTry 'cli foo --help' for help.\n\nError: No such option: -x\n" = <Result SystemExit(2)>.output
E        +    where <Result SystemExit(2)> = <bound method CliRunner.invoke of <click.testing.CliRunner object at 0x7f4b7e04f850>>(cli, ['-x'])
E        +      where <bound method CliRunner.invoke of <click.testing.CliRunner object at 0x7f4b7e04f850>> = <click.testing.CliRunner object at 0x7f4b7e04f850>.invoke

test.py:33: AssertionError
========================================================================= short test summary info ==========================================================================
FAILED test.py::test_default_command_with_arguments - assert 'no such option' in "Usage: cli foo [OPTIONS]\nTry 'cli foo --help' for help.\n\nError: No such option: -x\n"
======================================================================= 1 failed, 6 passed in 0.56s ========================================================================
pytest-xprocess reminder::Be sure to terminate the started process by running 'pytest --xkill' if you have not explicitly done so in your fixture with 'xprocess.getinfo(<process_name>).terminate()'.

The `--` mechanism for splitting arguments doesn't get forwarded correctly

Spotted this for my llm command, which uses click-default-group to set the default command to llm prompt.

If you run this:

llm -- '--help means what?'

You get this error:

Usage: llm prompt [OPTIONS] [PROMPT]
Try 'llm prompt --help' for help.

Error: No such option: --help means what?

But if you run the full command instead:

llm prompt -- '--help means what?'

You get the expected answer:

"--help" is a command that can be used in various computer programs and ...

Bug reported here:

Thanks

Just saying a quick thanks for this project. It was exactly what I needed, and I found it quickly with Google and the GitHub issue on the main repo. :)

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.