Skip to content

Commit

Permalink
feat: migrate commands to core24 (#4830)
Browse files Browse the repository at this point in the history
- `snapcraft list-plugins` no longer errors when in a core24 project
directory
- `snapcraft init` creates a core24 snapcraft.yaml file, instead of
core22
- `snapcraft list-plugins` shows core24 plugins when not in a snapcraft
project directory, instead of core22
- command reference docs are based on core24 lifecycle commands, instead
of core22

Signed-off-by: Callahan Kovacs <[email protected]>
  • Loading branch information
mr-cal authored Jun 4, 2024
1 parent 80bd4f0 commit 0bee372
Show file tree
Hide file tree
Showing 28 changed files with 516 additions and 625 deletions.
5 changes: 5 additions & 0 deletions docs/reference/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ provided, the command applies to all parts.

.. include:: commands/lifecycle-commands.rst

Plugins
----------

.. include:: commands/plugins-commands.rst

Extensions
----------

Expand Down
95 changes: 3 additions & 92 deletions snapcraft/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@

import snapcraft
import snapcraft_legacy
from snapcraft import cli, commands, errors, models, services
from snapcraft.commands import unimplemented
from snapcraft import cli, errors, models, services
from snapcraft.extensions import apply_extensions
from snapcraft.models.project import SnapcraftBuildPlanner, apply_root_packages
from snapcraft.parts import set_global_environment
Expand Down Expand Up @@ -272,96 +271,8 @@ def create_app() -> Snapcraft:
extra_loggers={"snapcraft.remote"},
)

app.add_command_group(
"Lifecycle",
[
craft_app_commands.lifecycle.CleanCommand,
craft_app_commands.lifecycle.PullCommand,
craft_app_commands.lifecycle.BuildCommand,
craft_app_commands.lifecycle.StageCommand,
craft_app_commands.lifecycle.PrimeCommand,
commands.PackCommand,
commands.SnapCommand, # Hidden (legacy compatibility)
commands.RemoteBuildCommand,
unimplemented.Plugins,
unimplemented.ListPlugins,
unimplemented.Try,
],
)
app.add_command_group(
"Extensions",
[
commands.ListExtensions,
commands.ExpandExtensions,
],
)
app.add_command_group(
"Store Account",
[
commands.StoreExportLoginCommand,
commands.StoreLoginCommand,
commands.StoreLogoutCommand,
commands.StoreWhoAmICommand,
],
)
app.add_command_group(
"Store Snap Names",
[
commands.StoreRegisterCommand,
commands.StoreNamesCommand,
commands.StoreLegacyListRegisteredCommand,
commands.StoreLegacyListCommand,
commands.StoreLegacyMetricsCommand,
commands.StoreLegacyUploadMetadataCommand,
],
)
app.add_command_group(
"Store Snap Release Management",
[
commands.StoreReleaseCommand,
commands.StoreCloseCommand,
commands.StoreStatusCommand,
commands.StoreUploadCommand,
commands.StoreLegacyPushCommand,
commands.StoreLegacyPromoteCommand,
commands.StoreListRevisionsCommand,
commands.StoreRevisionsCommand,
],
)
app.add_command_group(
"Store Snap Tracks",
[
commands.StoreListTracksCommand,
commands.StoreTracksCommand,
commands.StoreLegacySetDefaultTrackCommand,
],
)
app.add_command_group(
"Store Key Management",
[
commands.StoreLegacyCreateKeyCommand,
commands.StoreLegacyRegisterKeyCommand,
commands.StoreLegacySignBuildCommand,
commands.StoreLegacyListKeysCommand,
],
)
app.add_command_group(
"Store Validation Sets",
[
commands.StoreEditValidationSetsCommand,
commands.StoreLegacyListValidationSetsCommand,
commands.StoreLegacyValidateCommand,
commands.StoreLegacyGatedCommand,
],
)
app.add_command_group(
"Other",
list(craft_app_commands.get_other_command_group().commands)
+ [
commands.LintCommand,
unimplemented.Init,
],
)
for group in [cli.CORE24_LIFECYCLE_COMMAND_GROUP, *cli.COMMAND_GROUPS]:
app.add_command_group(group.name, group.commands)

return app

Expand Down
89 changes: 64 additions & 25 deletions snapcraft/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import contextlib
import os
import sys
from dataclasses import dataclass
from typing import Any, Dict

import craft_application.commands
import craft_cli
import craft_store
from craft_application.errors import RemoteBuildError
Expand All @@ -34,31 +36,61 @@
from . import commands
from .legacy_cli import run_legacy


@dataclass
class CommandGroup:
"""Dataclass to hold a command group."""

name: str
commands: list


CORE22_LIFECYCLE_COMMAND_GROUP = CommandGroup(
"Lifecycle",
[
commands.core22.CleanCommand,
commands.core22.PullCommand,
commands.core22.BuildCommand,
commands.core22.StageCommand,
commands.core22.PrimeCommand,
commands.core22.PackCommand,
commands.core22.SnapCommand, # hidden (legacy compatibility)
commands.core22.TryCommand,
],
)

CORE24_LIFECYCLE_COMMAND_GROUP = CommandGroup(
"Lifecycle",
[
craft_application.commands.lifecycle.CleanCommand,
craft_application.commands.lifecycle.PullCommand,
craft_application.commands.lifecycle.BuildCommand,
craft_application.commands.lifecycle.StageCommand,
craft_application.commands.lifecycle.PrimeCommand,
commands.PackCommand,
commands.SnapCommand, # Hidden (legacy compatibility)
commands.RemoteBuildCommand,
commands.TryCommand,
],
)

COMMAND_GROUPS = [
craft_cli.CommandGroup(
"Lifecycle",
CommandGroup(
"Plugins",
[
commands.core22.CleanCommand,
commands.core22.PullCommand,
commands.core22.BuildCommand,
commands.core22.StageCommand,
commands.core22.PrimeCommand,
commands.core22.PackCommand,
commands.core22.SnapCommand, # hidden (legacy compatibility)
commands.core22.PluginsCommand,
commands.core22.ListPluginsCommand,
commands.core22.TryCommand,
commands.PluginsCommand,
commands.ListPluginsCommand,
],
),
craft_cli.CommandGroup(
CommandGroup(
"Extensions",
[
commands.core22.ListExtensionsCommand,
commands.core22.ExtensionsCommand, # hidden (alias to list-extensions)
commands.core22.ExpandExtensionsCommand,
commands.ListExtensionsCommand,
commands.ExtensionsCommand, # hidden (alias to list-extensions)
commands.ExpandExtensionsCommand,
],
),
craft_cli.CommandGroup(
CommandGroup(
"Store Account",
[
commands.StoreLoginCommand,
Expand All @@ -67,7 +99,7 @@
commands.StoreWhoAmICommand,
],
),
craft_cli.CommandGroup(
CommandGroup(
"Store Snap Names",
[
commands.StoreRegisterCommand,
Expand All @@ -78,7 +110,7 @@
commands.StoreLegacyUploadMetadataCommand,
],
),
craft_cli.CommandGroup(
CommandGroup(
"Store Snap Release Management",
[
commands.StoreReleaseCommand,
Expand All @@ -91,15 +123,15 @@
commands.StoreRevisionsCommand, # hidden (alias to list-revisions)
],
),
craft_cli.CommandGroup(
CommandGroup(
"Store Snap Tracks",
[
commands.StoreListTracksCommand,
commands.StoreTracksCommand, # hidden (alias to list-tracks)
commands.StoreLegacySetDefaultTrackCommand,
],
),
craft_cli.CommandGroup(
CommandGroup(
"Store Key Management",
[
commands.StoreLegacyCreateKeyCommand,
Expand All @@ -108,7 +140,7 @@
commands.StoreLegacyListKeysCommand,
],
),
craft_cli.CommandGroup(
CommandGroup(
"Store Validation Sets",
[
commands.StoreEditValidationSetsCommand,
Expand All @@ -117,10 +149,12 @@
commands.StoreLegacyGatedCommand,
],
),
craft_cli.CommandGroup(
CommandGroup(
"Other",
[
commands.core22.InitCommand,
*craft_application.commands.get_other_command_group().commands,
commands.LintCommand,
commands.InitCommand,
],
),
]
Expand Down Expand Up @@ -171,9 +205,14 @@ def get_verbosity() -> EmitterMode:

def get_dispatcher() -> craft_cli.Dispatcher:
"""Return an instance of Dispatcher."""
craft_cli_command_groups = [
craft_cli.CommandGroup(group.name, group.commands)
for group in COMMAND_GROUPS + [CORE22_LIFECYCLE_COMMAND_GROUP]
]

return craft_cli.Dispatcher(
"snapcraft",
COMMAND_GROUPS,
craft_cli_command_groups,
summary="Package, distribute, and update snaps for Linux and IoT",
extra_global_args=GLOBAL_ARGS,
default_command=commands.core22.PackCommand,
Expand Down
19 changes: 15 additions & 4 deletions snapcraft/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
StoreLogoutCommand,
StoreWhoAmICommand,
)
from .extensions import ExpandExtensions, ListExtensions
from .extensions import (
ExpandExtensionsCommand,
ExtensionsCommand,
ListExtensionsCommand,
)
from .init import InitCommand
from .legacy import (
StoreLegacyCreateKeyCommand,
StoreLegacyGatedCommand,
Expand All @@ -37,7 +42,7 @@
StoreLegacyUploadMetadataCommand,
StoreLegacyValidateCommand,
)
from .lifecycle import PackCommand, SnapCommand
from .lifecycle import PackCommand, SnapCommand, TryCommand
from .lint import LintCommand
from .manage import StoreCloseCommand, StoreReleaseCommand
from .names import (
Expand All @@ -46,6 +51,7 @@
StoreNamesCommand,
StoreRegisterCommand,
)
from .plugins import ListPluginsCommand, PluginsCommand
from .remote import RemoteBuildCommand
from .status import (
StoreListRevisionsCommand,
Expand All @@ -58,11 +64,15 @@
from .validation_sets import StoreEditValidationSetsCommand

__all__ = [
"ExpandExtensions",
"ExpandExtensionsCommand",
"ExtensionsCommand",
"InitCommand",
"LintCommand",
"ListExtensions",
"ListExtensionsCommand",
"ListPluginsCommand",
"RemoteBuildCommand",
"PackCommand",
"PluginsCommand",
"SnapCommand",
"StoreCloseCommand",
"StoreEditValidationSetsCommand",
Expand Down Expand Up @@ -93,6 +103,7 @@
"StoreTracksCommand",
"StoreUploadCommand",
"StoreWhoAmICommand",
"TryCommand",
"core22",
"legacy",
]
13 changes: 0 additions & 13 deletions snapcraft/commands/core22/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@

"""Snapcraft commands for core22 base."""

from .discovery import ListPluginsCommand, PluginsCommand
from .extensions import (
ExpandExtensionsCommand,
ExtensionsCommand,
ListExtensionsCommand,
)
from .init import InitCommand
from .lifecycle import (
BuildCommand,
CleanCommand,
Expand All @@ -37,13 +30,7 @@
__all__ = [
"BuildCommand",
"CleanCommand",
"ExpandExtensionsCommand",
"ExtensionsCommand",
"InitCommand",
"ListExtensionsCommand",
"ListPluginsCommand",
"PackCommand",
"PluginsCommand",
"PrimeCommand",
"PullCommand",
"SnapCommand",
Expand Down
Loading

0 comments on commit 0bee372

Please sign in to comment.