From 95622b6198f6ebf35901bf05abcda83a79327137 Mon Sep 17 00:00:00 2001 From: Fabio Valentini Date: Tue, 10 Oct 2023 00:07:19 +0200 Subject: [PATCH] crate: exit gracefully on nonsensical command line arguments --- rust2rpm/__main__.py | 5 ++++- rust2rpm/crate.py | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/rust2rpm/__main__.py b/rust2rpm/__main__.py index 61697a7..f989986 100644 --- a/rust2rpm/__main__.py +++ b/rust2rpm/__main__.py @@ -8,7 +8,7 @@ from cargo2rpm.semver import Version from rust2rpm import log from rust2rpm.cli import get_parser from rust2rpm.conf import load_config -from rust2rpm.crate import process_project +from rust2rpm.crate import InvalidRequestError, process_project from rust2rpm.cratesio import NoVersionsError from rust2rpm.distgit import get_package_info from rust2rpm.generator import spec_render_crate, spec_render_project, spec_render_workspace @@ -53,6 +53,9 @@ def main(): except NoVersionsError: log.error(f"No versions are available for crate {args.crate!r}.") sys.exit(1) + except InvalidRequestError as exc: + log.error(str(exc)) + sys.exit(1) if metadata.is_workspace(): base_name = project diff --git a/rust2rpm/crate.py b/rust2rpm/crate.py index 07f4df7..dbc15f7 100644 --- a/rust2rpm/crate.py +++ b/rust2rpm/crate.py @@ -54,6 +54,10 @@ DOC_FILE_PATTERN = re.compile( DOC_FILE_EXCLUDES = re.compile(r"CMakeLists\.txt|versions\.txt|.*\.tpl|.*\.in") +class InvalidRequestError(ValueError): + pass + + def local_toml_file(toml_path: str) -> tuple[str, list[str], list[str]]: assert os.path.isfile(toml_path) assert os.path.basename(toml_path) == "Cargo.toml" @@ -256,7 +260,7 @@ def process_project( if project_is_path(project) and not project.endswith(".crate"): # project points into unpacked sources: if store_crate: - raise ValueError("The '--store-crate' / '-s' flag cannot be used for unpacked sources.") + raise InvalidRequestError("The '--store-crate' / '-s' flag cannot be used for unpacked sources.") # process unpacked sources name, version, diffs, metadata, doc_files, license_files, vendor_tarball = process_project_local(