From a2f19e33c12a9e9498d15bda9e69e198155a0660 Mon Sep 17 00:00:00 2001 From: Matthias Dellweg Date: Mon, 30 Aug 2021 13:57:12 +0200 Subject: [PATCH] Refactor chunk size option callback [noissue] --- pulpcore/cli/common/generic.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/pulpcore/cli/common/generic.py b/pulpcore/cli/common/generic.py index 9844f84b7..c5466f590 100644 --- a/pulpcore/cli/common/generic.py +++ b/pulpcore/cli/common/generic.py @@ -240,13 +240,10 @@ def _callback( def parse_size_callback(ctx: click.Context, param: click.Parameter, value: str) -> int: size = value.strip().upper() - if not size or not re.match(r"^\s*([0-9]*)\s*([KMGT]?B)?\s*$", size): - raise click.ClickException("Please pass in a valid size of form: [0-9] [K/M/G]B") - size = re.sub(r"([KMGT]?B)", r" \1", size) - chunk = [string.strip() for string in size.split()] - if len(chunk) == 1: - chunk.append("B") - number, unit = chunk + match = re.match(r"^([0-9]+)\s*([KMGT]?B)?$", size) + if not match: + raise click.ClickException("Please pass in a valid size of form: [0-9] [K/M/G/T]B") + number, unit = match.groups(default="B") return int(float(number) * units[unit])