summaryrefslogtreecommitdiff
path: root/cmd2/argparse_custom.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2021-04-06 16:48:08 -0400
committeranselor <anselor@gmail.com>2021-04-13 11:08:43 -0400
commit83a5ec0a0bdfc81efcc162478909862420d234a1 (patch)
tree5a753f8cb45695c71fab79df85f49a37d4ab2440 /cmd2/argparse_custom.py
parente8b6456fc73a6f7bdb176251a1539a1886659f32 (diff)
downloadcmd2-git-83a5ec0a0bdfc81efcc162478909862420d234a1.tar.gz
Updated main code to use f-strings
Diffstat (limited to 'cmd2/argparse_custom.py')
-rw-r--r--cmd2/argparse_custom.py22
1 files changed, 10 insertions, 12 deletions
diff --git a/cmd2/argparse_custom.py b/cmd2/argparse_custom.py
index 6b1c799d..4ba05985 100644
--- a/cmd2/argparse_custom.py
+++ b/cmd2/argparse_custom.py
@@ -256,18 +256,16 @@ def generate_range_error(range_min: int, range_max: Union[int, float]) -> str:
err_str = "expected "
if range_max == constants.INFINITY:
- err_str += "at least {} argument".format(range_min)
-
- if range_min != 1:
- err_str += "s"
+ plural = '' if range_min == 1 else 's'
+ err_str += f"at least {range_min}"
else:
+ plural = '' if range_max == 1 else 's'
if range_min == range_max:
- err_str += "{} argument".format(range_min)
+ err_str += f"{range_min}"
else:
- err_str += "{} to {} argument".format(range_min, range_max)
+ err_str += f"{range_min} to {range_max}"
- if range_max != 1:
- err_str += "s"
+ err_str += f" argument{plural}"
return err_str
@@ -600,7 +598,7 @@ def _get_nargs_pattern_wrapper(self: argparse.ArgumentParser, action: argparse.A
else:
range_max = nargs_range[1]
- nargs_pattern = '(-*A{{{},{}}}-*)'.format(nargs_range[0], range_max)
+ nargs_pattern = f'(-*A{{{nargs_range[0]},{range_max}}}-*)'
# if this is an optional action, -- is not allowed
if action.option_strings:
@@ -881,9 +879,9 @@ class Cmd2HelpFormatter(argparse.RawTextHelpFormatter):
nargs_range = getattr(action, ATTR_NARGS_RANGE, None)
if nargs_range is not None:
if nargs_range[1] == constants.INFINITY:
- range_str = '{}+'.format(nargs_range[0])
+ range_str = f'{nargs_range[0]}+'
else:
- range_str = '{}..{}'.format(nargs_range[0], nargs_range[1])
+ range_str = f'{nargs_range[0]}..{nargs_range[1]}'
return '{}{{{}}}'.format('%s' % metavar_formatter(1), range_str)
@@ -960,7 +958,7 @@ class Cmd2ArgumentParser(argparse.ArgumentParser):
self.print_usage(sys.stderr)
formatted_message = ansi.style_error(formatted_message)
- self.exit(2, '{}\n\n'.format(formatted_message))
+ self.exit(2, f'{formatted_message}\n\n')
# noinspection PyProtectedMember
def format_help(self) -> str: