Skip to content

Commit

Permalink
feat: add improved bash completion script
Browse files Browse the repository at this point in the history
  • Loading branch information
bepri committed Jan 24, 2025
1 parent 8ea35b0 commit ec70866
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 11 additions & 2 deletions rockcraft/cli.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
5 changes: 5 additions & 0 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ platforms:
apps:
rockcraft:
command: bin/python $SNAP/bin/rockcraft
completer: completion.sh
skopeo:
command: bin/skopeo

Expand Down Expand Up @@ -126,6 +127,10 @@ parts:
uv export --no-dev --no-emit-workspace --no-emit-package pywin32 --output-file uv-requirements.txt
${SNAP}/libexec/snapcraft/craftctl default
PYTHONPATH=/root/parts/$CRAFT_PART_NAME/install/lib/python3.12/site-packages \
python3 -m craft_cli.completion $CRAFT_PROJECT_NAME rockcraft.cli:get_app_info \
> $CRAFT_PART_INSTALL/completion.sh
version="$("${CRAFT_STAGE}/usr/bin/python3" -c "import rockcraft;print(rockcraft.__version__)")"
${SNAP}/libexec/snapcraft/craftctl set version="$version"
[ -n "$(echo $version | grep "post")" ] && grade=devel || grade=stable
Expand Down

0 comments on commit ec70866

Please sign in to comment.