|
| 1 | +import click |
| 2 | + |
| 3 | +from pulp_glue.common.i18n import get_translation |
| 4 | +from pulp_glue.rust.context import ( |
| 5 | + PulpRustDistributionContext, |
| 6 | + PulpRustRemoteContext, |
| 7 | + PulpRustRepositoryContext, |
| 8 | +) |
| 9 | + |
| 10 | +from pulp_cli.generic import ( |
| 11 | + PulpCLIContext, |
| 12 | + common_distribution_create_options, |
| 13 | + content_guard_option, |
| 14 | + create_command, |
| 15 | + destroy_command, |
| 16 | + distribution_filter_options, |
| 17 | + distribution_lookup_option, |
| 18 | + href_option, |
| 19 | + label_command, |
| 20 | + list_command, |
| 21 | + name_option, |
| 22 | + pass_pulp_context, |
| 23 | + pulp_group, |
| 24 | + pulp_labels_option, |
| 25 | + pulp_option, |
| 26 | + resource_option, |
| 27 | + show_command, |
| 28 | + update_command, |
| 29 | +) |
| 30 | + |
| 31 | +translation = get_translation(__package__) |
| 32 | +_ = translation.gettext |
| 33 | + |
| 34 | + |
| 35 | +repository_option = resource_option( |
| 36 | + "--repository", |
| 37 | + default_plugin="rust", |
| 38 | + default_type="rust", |
| 39 | + context_table={"rust:rust": PulpRustRepositoryContext}, |
| 40 | + href_pattern=PulpRustRepositoryContext.HREF_PATTERN, |
| 41 | + help=_( |
| 42 | + "Repository to be used for auto-distributing." |
| 43 | + " Specified as '[[<plugin>:]<type>:]<name>' or as href." |
| 44 | + ), |
| 45 | +) |
| 46 | + |
| 47 | + |
| 48 | +@pulp_group() |
| 49 | +@click.option( |
| 50 | + "-t", |
| 51 | + "--type", |
| 52 | + "distribution_type", |
| 53 | + type=click.Choice(["rust"], case_sensitive=False), |
| 54 | + default="rust", |
| 55 | +) |
| 56 | +@pass_pulp_context |
| 57 | +@click.pass_context |
| 58 | +def distribution(ctx: click.Context, pulp_ctx: PulpCLIContext, /, distribution_type: str) -> None: |
| 59 | + if distribution_type == "rust": |
| 60 | + ctx.obj = PulpRustDistributionContext(pulp_ctx) |
| 61 | + else: |
| 62 | + raise NotImplementedError() |
| 63 | + |
| 64 | + |
| 65 | +lookup_options = [href_option, name_option, distribution_lookup_option] |
| 66 | +nested_lookup_options = [distribution_lookup_option] |
| 67 | +update_options = [ |
| 68 | + repository_option, |
| 69 | + pulp_option( |
| 70 | + "--version", |
| 71 | + type=int, |
| 72 | + help=_( |
| 73 | + "The repository version number to distribute." |
| 74 | + " When unset, the latest version of the repository will be auto-distributed." |
| 75 | + ), |
| 76 | + ), |
| 77 | + resource_option( |
| 78 | + "--remote", |
| 79 | + default_plugin="rust", |
| 80 | + default_type="rust", |
| 81 | + context_table={"rust:rust": PulpRustRemoteContext}, |
| 82 | + href_pattern=PulpRustRemoteContext.HREF_PATTERN, |
| 83 | + help=_( |
| 84 | + "Remote to use for pull-through caching." |
| 85 | + " Specified as '[[<plugin>:]<type>:]<name>' or as href." |
| 86 | + ), |
| 87 | + ), |
| 88 | + content_guard_option, |
| 89 | + pulp_labels_option, |
| 90 | +] |
| 91 | +create_options = common_distribution_create_options + update_options |
| 92 | + |
| 93 | +distribution.add_command(list_command(decorators=distribution_filter_options)) |
| 94 | +distribution.add_command(show_command(decorators=lookup_options)) |
| 95 | +distribution.add_command(create_command(decorators=create_options)) |
| 96 | +distribution.add_command( |
| 97 | + update_command(decorators=lookup_options + update_options + [click.option("--base-path")]) |
| 98 | +) |
| 99 | +distribution.add_command(destroy_command(decorators=lookup_options)) |
| 100 | +distribution.add_command(label_command(decorators=nested_lookup_options)) |
0 commit comments