diff --git a/pyproject.toml b/pyproject.toml index fbf708e09..cc5259d96 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ classifiers = [ dependencies = [ "craft-application~=4.6.0", "craft-archives>=2.0.0", - "craft-cli", + "craft-cli>=2.15.0", "craft-parts~=2.1.4", "craft-platforms~=0.3", "craft-providers>=2.0.4", diff --git a/rockcraft/cli.py b/rockcraft/cli.py index 7a5221e61..0ba967433 100644 --- a/rockcraft/cli.py +++ b/rockcraft/cli.py @@ -1,6 +1,6 @@ # -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- # -# Copyright 2021-2022 Canonical Ltd. +# Copyright 2021-2025 Canonical Ltd. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 as @@ -16,9 +16,10 @@ """Command-line application entry point.""" -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any from craft_application import commands as appcommands +from craft_cli import Dispatcher from . import commands from .services import RockcraftServiceFactory @@ -59,3 +60,11 @@ def _create_app() -> "Rockcraft": app.add_command_group("Lifecycle", [appcommands.RemoteBuild]) return app + + +def get_app_info() -> tuple[Dispatcher, dict[str, Any]]: + """Retrieve application info. Used by craft-cli's completion module.""" + app = _create_app() + dispatcher = app._create_dispatcher() + + return dispatcher, app.app_config diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 16399e05e..ac408941d 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -25,6 +25,7 @@ platforms: apps: rockcraft: command: bin/python $SNAP/bin/rockcraft + completer: completion.sh skopeo: command: bin/skopeo @@ -136,6 +137,15 @@ parts: - rockcraft-libs - libgit2 + bash-completion: + after: [rockcraft] + plugin: nil + build-environment: + - PYTHONPATH: $CRAFT_STAGE/lib/python3.12/site-packages + override-build: | + python3 -m craft_cli.completion $CRAFT_PROJECT_NAME rockcraft.cli:get_app_info \ + > $CRAFT_PART_INSTALL/completion.sh + umoci: plugin: make source: https://github.com/opencontainers/umoci.git diff --git a/uv.lock b/uv.lock index ef592844e..b877012ec 100644 --- a/uv.lock +++ b/uv.lock @@ -572,16 +572,19 @@ wheels = [ [[package]] name = "craft-cli" -version = "2.13.0" +version = "2.15.0" source = { registry = "https://pypi.org/simple" } dependencies = [ + { name = "jinja2" }, + { name = "overrides" }, { name = "platformdirs" }, { name = "pywin32", marker = "sys_platform == 'win32' or (extra == 'extra-9-rockcraft-apt-jammy' and extra == 'extra-9-rockcraft-apt-noble') or (extra == 'extra-9-rockcraft-apt-jammy' and extra == 'extra-9-rockcraft-apt-oracular') or (extra == 'extra-9-rockcraft-apt-jammy' and extra == 'extra-9-rockcraft-apt-plucky') or (extra == 'extra-9-rockcraft-apt-noble' and extra == 'extra-9-rockcraft-apt-oracular') or (extra == 'extra-9-rockcraft-apt-noble' and extra == 'extra-9-rockcraft-apt-plucky') or (extra == 'extra-9-rockcraft-apt-oracular' and extra == 'extra-9-rockcraft-apt-plucky')" }, { name = "pyyaml" }, + { name = "typing-extensions" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/9f/1f/cd622c8218adea214e11224f1dfa581242a307a023c9997f085ef0d9d1e0/craft_cli-2.13.0.tar.gz", hash = "sha256:a53575dde5bc4284cba49573093eb940584ad3520aa989271345770e4f6f5172", size = 108894 } +sdist = { url = "https://files.pythonhosted.org/packages/9e/a7/32b8170deaefb28a8ec4cbccbaa0fbc4fac019cf3edf3682079af271ffa9/craft_cli-2.15.0.tar.gz", hash = "sha256:83c94e521c597c0836eb4a649c68105827006731d2032ca925cf1aea27d9fc9c", size = 116960 } wheels = [ - { url = "https://files.pythonhosted.org/packages/27/ae/59258afc5c5da165707673780b75171a28386836b7cf8f256a72b30e5db0/craft_cli-2.13.0-py3-none-any.whl", hash = "sha256:f390d7926020b0b7aed1d01ff83f6f8ba5a875f3a50dc4004f4c88774f2ac0cd", size = 39885 }, + { url = "https://files.pythonhosted.org/packages/f8/1c/9786bc93f1d210eadf6513868d27b75996ab6c3a40013782a4be86f5a98e/craft_cli-2.15.0-py3-none-any.whl", hash = "sha256:4ed2f7e409acce8f66a60d7038645431b38b2320d2eb88e133b7b9af1ce9843a", size = 46437 }, ] [[package]] @@ -1012,14 +1015,14 @@ wheels = [ [[package]] name = "jinja2" -version = "3.1.4" +version = "3.1.5" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "markupsafe" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/ed/55/39036716d19cab0747a5020fc7e907f362fbf48c984b14e62127f7e68e5d/jinja2-3.1.4.tar.gz", hash = "sha256:4a3aee7acbbe7303aede8e9648d13b8bf88a429282aa6122a993f0ac800cb369", size = 240245 } +sdist = { url = "https://files.pythonhosted.org/packages/af/92/b3130cbbf5591acf9ade8708c365f3238046ac7cb8ccba6e81abccb0ccff/jinja2-3.1.5.tar.gz", hash = "sha256:8fefff8dc3034e27bb80d67c671eb8a9bc424c0ef4c0826edbff304cceff43bb", size = 244674 } wheels = [ - { url = "https://files.pythonhosted.org/packages/31/80/3a54838c3fb461f6fec263ebf3a3a41771bd05190238de3486aae8540c36/jinja2-3.1.4-py3-none-any.whl", hash = "sha256:bc5dd2abb727a5319567b7a813e6a2e7318c39f4f487cfe6c89c6f9c7d25197d", size = 133271 }, + { url = "https://files.pythonhosted.org/packages/bd/0f/2ba5fbcd631e3e88689309dbe978c5769e883e4b84ebfe7da30b43275c5a/jinja2-3.1.5-py3-none-any.whl", hash = "sha256:aba0f4dc9ed8013c424088f68a5c226f7d6097ed89b246d7749c2ec4175c6adb", size = 134596 }, ] [[package]] @@ -2415,7 +2418,7 @@ requires-dist = [ { name = "coverage", marker = "extra == 'dev'" }, { name = "craft-application", specifier = "~=4.6.0" }, { name = "craft-archives", specifier = ">=2.0.0" }, - { name = "craft-cli" }, + { name = "craft-cli", specifier = ">=2.15.0" }, { name = "craft-parts", specifier = "~=2.1.4" }, { name = "craft-platforms", specifier = "~=0.3" }, { name = "craft-providers", specifier = ">=2.0.4" },