Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add improved bash completion script #793

Merged
merged 7 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
mr-cal marked this conversation as resolved.
Show resolved Hide resolved
"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
4 changes: 1 addition & 3 deletions rockcraft/pebble.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ class Pebble:
"stage-snaps": ["pebble/latest/stable"],
# We need this because "services" is Optional, but the directory must exist
"override-prime": str(
"craftctl default\n"
f"mkdir -p {PEBBLE_LAYERS_PATH}\n"
f"chmod 777 {PEBBLE_PATH}"
f"craftctl default\nmkdir -p {PEBBLE_LAYERS_PATH}\nchmod 777 {PEBBLE_PATH}"
),
}
PEBBLE_PART_SPEC = {
Expand Down
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 \
mr-cal marked this conversation as resolved.
Show resolved Hide resolved
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
Loading