From b186b1f67a9f82b04e727ef9cc3fabe7abc28c63 Mon Sep 17 00:00:00 2001 From: Charles Short Date: Sun, 20 Aug 2023 11:51:51 -0400 Subject: [PATCH] Remove duplicate code Using click's "required" argument checks to see if the value is passed or not. Therefore we can check before flag before running a command. So we can remove duplicate code. Story: 2010867 Task: 48556 Change-Id: Ie07d8ff921c8b883d323f8bbc062ce1130039848 Signed-off-by: Charles Short --- apt_ostree/cmd/compose/create.py | 13 +------------ apt_ostree/cmd/options.py | 1 + 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/apt_ostree/cmd/compose/create.py b/apt_ostree/cmd/compose/create.py index d210cbb..4313b96 100644 --- a/apt_ostree/cmd/compose/create.py +++ b/apt_ostree/cmd/compose/create.py @@ -23,10 +23,6 @@ from apt_ostree.utils import run_command @pass_state_context @compose_options def create(state, repo, base, branch, edit): - if state.repo is None: - click.secho("You did not supply an ostree repository", fg="red") - sys.exit(1) - if not state.repo.exists(): click.secho(f"Creating ostree repository: {state.repo}") run_command(["ostree", "init", f"--repo={state.repo}", @@ -34,19 +30,12 @@ def create(state, repo, base, branch, edit): else: click.secho(f"Found ostree repository: {state.repo}") - if state.branch is None: - click.secho("You did not supply an ostree branch.", fg="red") - sys.exit(1) click.secho(f"Found ostree branch: {state.branch}") - if state.base is None: - click.secho("You did not supply a configuration directory.", fg="red") - sys.exit(1) if not state.base.exists(): click.secho("Configuration directory does not exist.", fg="red") sys.exit(1) - else: - click.secho(f"Found configuration directory: {state.base}") + click.secho(f"Found configuration directory: {state.base}") config = state.base.joinpath("bootstrap.yaml") if not config.exists(): diff --git a/apt_ostree/cmd/options.py b/apt_ostree/cmd/options.py index d51c4ed..c8dc39a 100644 --- a/apt_ostree/cmd/options.py +++ b/apt_ostree/cmd/options.py @@ -97,6 +97,7 @@ def branch_option(f): return click.argument( "branch", nargs=1, + required=True, callback=callback )(f)