Skip to content

Commit eb6763f

Browse files
Chris PattersonSergio Schvezov
andauthored
cli: merge build options into provider options (#2977)
In reality these options only work with specific providers. Merge the build options and provider option lists to simplify the option handling code. Signed-off-by: Chris Patterson <chris.patterson@canonical.com> Co-authored-by: Sergio Schvezov <sergio.schvezov@canonical.com>
1 parent 6e8e80c commit eb6763f

3 files changed

Lines changed: 9 additions & 24 deletions

File tree

snapcraft/cli/_options.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,33 +45,34 @@ def prompt_for_value(self, ctx):
4545
)
4646

4747

48-
_BUILD_OPTIONS = [
48+
_SUPPORTED_PROVIDERS = ["host", "lxd", "multipass"]
49+
_HIDDEN_PROVIDERS = ["managed-host"]
50+
_ALL_PROVIDERS = _SUPPORTED_PROVIDERS + _HIDDEN_PROVIDERS
51+
_PROVIDER_OPTIONS = [
4952
dict(
5053
param_decls="--target-arch",
5154
metavar="<arch>",
5255
help="Target architecture to cross compile to",
56+
supported_providers=["host", "lxd", "managed-host", "multipass"],
5357
),
5458
dict(
5559
param_decls="--debug",
5660
is_flag=True,
5761
help="Shells into the environment if the build fails.",
62+
supported_providers=["host", "lxd", "managed-host", "multipass"],
5863
),
5964
dict(
6065
param_decls="--shell",
6166
is_flag=True,
6267
help="Shells into the environment in lieu of the step to run.",
68+
supported_providers=["host", "lxd", "managed-host", "multipass"],
6369
),
6470
dict(
6571
param_decls="--shell-after",
6672
is_flag=True,
6773
help="Shells into the environment after the step has run.",
74+
supported_providers=["host", "lxd", "managed-host", "multipass"],
6875
),
69-
]
70-
71-
_SUPPORTED_PROVIDERS = ["host", "lxd", "multipass"]
72-
_HIDDEN_PROVIDERS = ["managed-host"]
73-
_ALL_PROVIDERS = _SUPPORTED_PROVIDERS + _HIDDEN_PROVIDERS
74-
_PROVIDER_OPTIONS = [
7576
dict(
7677
param_decls="--destructive-mode",
7778
is_flag=True,
@@ -142,13 +143,6 @@ def _add_options(options, func, hidden):
142143
return func
143144

144145

145-
def add_build_options(hidden=False):
146-
def _add_build_options(func):
147-
return _add_options(_BUILD_OPTIONS, func, hidden)
148-
149-
return _add_build_options
150-
151-
152146
def add_provider_options(hidden=False):
153147
def _add_provider_options(func):
154148
return _add_options(_PROVIDER_OPTIONS, func, hidden)

snapcraft/cli/_runner.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from .version import versioncli, SNAPCRAFT_VERSION_TEMPLATE
3737
from .ci import cicli
3838
from ._command_group import SnapcraftGroup
39-
from ._options import add_build_options, add_provider_options
39+
from ._options import add_provider_options
4040
from ._errors import exception_handler
4141

4242

@@ -65,7 +65,6 @@
6565
message=SNAPCRAFT_VERSION_TEMPLATE, version=snapcraft.__version__ # type: ignore
6666
)
6767
@click.pass_context
68-
@add_build_options(hidden=True)
6968
@add_provider_options(hidden=True)
7069
@click.option("--debug", "-d", is_flag=True)
7170
@enable_snapcraft_config_file()

snapcraft/cli/lifecycle.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from ._command import SnapcraftProjectCommand
2626
from ._config import enable_snapcraft_config_file
2727
from ._options import (
28-
add_build_options,
2928
add_provider_options,
3029
apply_host_provider_flags,
3130
get_build_provider,
@@ -157,7 +156,6 @@ def _retrieve_provider_error(instance) -> None:
157156

158157

159158
@click.group()
160-
@add_build_options()
161159
@add_provider_options()
162160
@click.pass_context
163161
def lifecyclecli(ctx, **kwargs):
@@ -179,7 +177,6 @@ def init():
179177
@lifecyclecli.command(cls=SnapcraftProjectCommand)
180178
@enable_snapcraft_config_file()
181179
@click.pass_context
182-
@add_build_options()
183180
@add_provider_options()
184181
@click.argument("parts", nargs=-1, metavar="<part>...", required=False)
185182
def pull(ctx, parts, **kwargs):
@@ -196,7 +193,6 @@ def pull(ctx, parts, **kwargs):
196193

197194
@lifecyclecli.command(cls=SnapcraftProjectCommand)
198195
@enable_snapcraft_config_file()
199-
@add_build_options()
200196
@add_provider_options()
201197
@click.argument("parts", nargs=-1, metavar="<part>...", required=False)
202198
def build(parts, **kwargs):
@@ -213,7 +209,6 @@ def build(parts, **kwargs):
213209

214210
@lifecyclecli.command(cls=SnapcraftProjectCommand)
215211
@enable_snapcraft_config_file()
216-
@add_build_options()
217212
@add_provider_options()
218213
@click.argument("parts", nargs=-1, metavar="<part>...", required=False)
219214
def stage(parts, **kwargs):
@@ -230,7 +225,6 @@ def stage(parts, **kwargs):
230225

231226
@lifecyclecli.command(cls=SnapcraftProjectCommand)
232227
@enable_snapcraft_config_file()
233-
@add_build_options()
234228
@add_provider_options()
235229
@click.argument("parts", nargs=-1, metavar="<part>...", required=False)
236230
def prime(parts, **kwargs):
@@ -247,7 +241,6 @@ def prime(parts, **kwargs):
247241

248242
@lifecyclecli.command("try")
249243
@enable_snapcraft_config_file()
250-
@add_build_options()
251244
@add_provider_options()
252245
def try_command(**kwargs):
253246
"""Try a snap on the host, priming if necessary.
@@ -266,7 +259,6 @@ def try_command(**kwargs):
266259

267260
@lifecyclecli.command(cls=SnapcraftProjectCommand)
268261
@enable_snapcraft_config_file()
269-
@add_build_options()
270262
@add_provider_options()
271263
@click.argument("directory", required=False)
272264
@click.option("--output", "-o", help="path to the resulting snap.")

0 commit comments

Comments
 (0)