Skip to content

Commit

Permalink
Refactor chunk size option callback
Browse files Browse the repository at this point in the history
[noissue]
  • Loading branch information
mdellweg committed Sep 2, 2021
1 parent 49bb141 commit a2f19e3
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions pulpcore/cli/common/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])


Expand Down

0 comments on commit a2f19e3

Please sign in to comment.