{"id":1418,"library":"click-default-group","title":"click-default-group","description":"click-default-group is an extension for the Click command-line interface framework that allows you to specify a default subcommand for a Click group. This means if a user invokes the group without any arguments, the default command will be executed. The current version is 1.2.4, and as a stable Click extension, it typically has an infrequent release cadence.","status":"active","version":"1.2.4","language":"en","source_language":"en","source_url":"https://github.com/click-contrib/click-default-group","tags":["click","cli","command-line-interface","default command","extension"],"install":[{"cmd":"pip install click-default-group","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core functionality is built on Click groups.","package":"click"}],"imports":[{"symbol":"DefaultGroup","correct":"from click_default_group import DefaultGroup"}],"quickstart":{"code":"import click\nfrom click_default_group import DefaultGroup\n\n@click.group(cls=DefaultGroup, default_if_no_args=True)\ndef cli():\n    \"\"\"A simple CLI with a default command.\"\"\"\n    pass\n\n@cli.command()\ndef foo():\n    click.echo(\"Running 'foo' command\")\n\n@cli.command(default=True)\ndef bar():\n    click.echo(\"Running 'bar' (default) command\")\n\nif __name__ == '__main__':\n    # Test cases:\n    # cli() should run 'bar'\n    # cli(['foo']) should run 'foo'\n    # cli(['bar']) should run 'bar'\n    print(\"\\n--- Invoking CLI without arguments (should run 'bar') ---\")\n    cli.main(args=[], standalone_mode=False)\n\n    print(\"\\n--- Invoking CLI with 'foo' argument ---\")\n    cli.main(args=['foo'], standalone_mode=False)\n\n    print(\"\\n--- Invoking CLI with 'bar' argument ---\")\n    cli.main(args=['bar'], standalone_mode=False)\n","lang":"python","description":"This example demonstrates how to create a `click` group using `DefaultGroup` and specify a default command (`bar`) that runs when the group is invoked without any subcommands. It includes `cli.main` calls for easy testing."},"warnings":[{"fix":"Add `default_if_no_args=True` to your `@click.group` decorator, e.g., `@click.group(cls=DefaultGroup, default_if_no_args=True)`.","message":"When using `DefaultGroup`, ensure you set `default_if_no_args=True` in the `@click.group` decorator if you want the default command to run when the group is invoked without any arguments. Otherwise, the group will simply display its help message if no subcommand is given, which often defeats the purpose of a default command.","severity":"gotcha","affected_versions":"All versions of click-default-group."},{"fix":"Specify a compatible `click` version in your `requirements.txt` or `pyproject.toml`, e.g., `click>=8.0.0,<9.0.0`.","message":"`click-default-group` relies on Click's internal API for group behavior. While generally stable, ensure compatibility by pinning your `click` dependency to a known working version range, especially when upgrading Click to a new major version, to avoid potential unexpected behavior.","severity":"gotcha","affected_versions":"All versions, especially during Click major version upgrades of Click."},{"fix":"Migrate to Python 3.7 or newer. Test your application thoroughly after migration.","message":"Although `click-default-group` theoretically supports Python 2.7 according to its metadata, Python 2.7 is long End-of-Life and unsupported. It is strongly recommended to use Python 3.7+ for all new development and to ensure all dependencies are also Python 3 compatible.","severity":"deprecated","affected_versions":"Projects considering Python 2.7."}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}