Skip to content

Commit

Permalink
refactor: use craft-cli command groups
Browse files Browse the repository at this point in the history
CommandGroups can be used now that craft-application will accept a
sequence of commands.
See canonical/craft-application#359

Signed-off-by: Callahan Kovacs <callahan.kovacs@canonical.com>
  • Loading branch information
mr-cal committed Aug 29, 2024
1 parent ad3b54b commit 41bf896
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions snapcraft/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import contextlib
import os
import sys
from dataclasses import dataclass
from typing import Any, Dict

import craft_application.commands
Expand All @@ -37,16 +36,7 @@
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(
CORE22_LIFECYCLE_COMMAND_GROUP = craft_cli.CommandGroup(
"Lifecycle",
[
commands.core22.CleanCommand,
Expand All @@ -60,7 +50,7 @@ class CommandGroup:
],
)

CORE24_LIFECYCLE_COMMAND_GROUP = CommandGroup(
CORE24_LIFECYCLE_COMMAND_GROUP = craft_cli.CommandGroup(
"Lifecycle",
[
craft_application.commands.lifecycle.CleanCommand,
Expand All @@ -76,22 +66,22 @@ class CommandGroup:
)

COMMAND_GROUPS = [
CommandGroup(
craft_cli.CommandGroup(
"Plugins",
[
commands.PluginsCommand,
commands.ListPluginsCommand,
],
),
CommandGroup(
craft_cli.CommandGroup(
"Extensions",
[
commands.ListExtensionsCommand,
commands.ExtensionsCommand, # hidden (alias to list-extensions)
commands.ExpandExtensionsCommand,
],
),
CommandGroup(
craft_cli.CommandGroup(
"Store Account",
[
commands.StoreLoginCommand,
Expand All @@ -100,7 +90,7 @@ class CommandGroup:
commands.StoreWhoAmICommand,
],
),
CommandGroup(
craft_cli.CommandGroup(
"Store Snap Names",
[
commands.StoreRegisterCommand,
Expand All @@ -111,7 +101,7 @@ class CommandGroup:
commands.StoreLegacyUploadMetadataCommand,
],
),
CommandGroup(
craft_cli.CommandGroup(
"Store Snap Release Management",
[
commands.StoreReleaseCommand,
Expand All @@ -124,15 +114,15 @@ class CommandGroup:
commands.StoreRevisionsCommand, # hidden (alias to list-revisions)
],
),
CommandGroup(
craft_cli.CommandGroup(
"Store Snap Tracks",
[
commands.StoreListTracksCommand,
commands.StoreTracksCommand, # hidden (alias to list-tracks)
commands.StoreLegacySetDefaultTrackCommand,
],
),
CommandGroup(
craft_cli.CommandGroup(
"Store Key Management",
[
commands.StoreLegacyCreateKeyCommand,
Expand All @@ -141,7 +131,7 @@ class CommandGroup:
commands.StoreLegacyListKeysCommand,
],
),
CommandGroup(
craft_cli.CommandGroup(
"Store Validation Sets",
[
commands.StoreEditValidationSetsCommand,
Expand All @@ -150,7 +140,7 @@ class CommandGroup:
commands.StoreLegacyGatedCommand,
],
),
CommandGroup(
craft_cli.CommandGroup(
"Other",
[
*craft_application.commands.get_other_command_group().commands,
Expand Down Expand Up @@ -206,10 +196,7 @@ 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]
]
craft_cli_command_groups = [*COMMAND_GROUPS, CORE22_LIFECYCLE_COMMAND_GROUP]

return craft_cli.Dispatcher(
"snapcraft",
Expand Down

0 comments on commit 41bf896

Please sign in to comment.