Skip to content

Commit 3e70716

Browse files
committed
Changed quote style to double.
1 parent beb4550 commit 3e70716

80 files changed

Lines changed: 3609 additions & 3609 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd2/__init__.py

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -65,56 +65,56 @@
6565
)
6666

6767
__all__: list[str] = [ # noqa: RUF022
68-
'COMMAND_NAME',
69-
'DEFAULT_SHORTCUTS',
68+
"COMMAND_NAME",
69+
"DEFAULT_SHORTCUTS",
7070
# Argparse Exports
71-
'Cmd2ArgumentParser',
72-
'register_argparse_argument_parameter',
73-
'set_default_ap_completer_type',
74-
'set_default_argument_parser_type',
71+
"Cmd2ArgumentParser",
72+
"register_argparse_argument_parameter",
73+
"set_default_ap_completer_type",
74+
"set_default_argument_parser_type",
7575
# Cmd2
76-
'Cmd',
77-
'CommandResult',
78-
'CommandSet',
79-
'Statement',
76+
"Cmd",
77+
"CommandResult",
78+
"CommandSet",
79+
"Statement",
8080
# Colors
81-
'Color',
81+
"Color",
8282
# Completion
83-
'Choices',
84-
'CompletionItem',
85-
'Completions',
83+
"Choices",
84+
"CompletionItem",
85+
"Completions",
8686
# Decorators
87-
'with_argument_list',
88-
'with_argparser',
89-
'with_category',
90-
'as_subcommand_to',
87+
"with_argument_list",
88+
"with_argparser",
89+
"with_category",
90+
"as_subcommand_to",
9191
# Exceptions
92-
'Cmd2ArgparseError',
93-
'CommandSetRegistrationError',
94-
'CompletionError',
95-
'PassThroughException',
96-
'SkipPostcommandHooks',
92+
"Cmd2ArgparseError",
93+
"CommandSetRegistrationError",
94+
"CompletionError",
95+
"PassThroughException",
96+
"SkipPostcommandHooks",
9797
# modules
98-
'plugin',
99-
'rich_utils',
100-
'string_utils',
98+
"plugin",
99+
"rich_utils",
100+
"string_utils",
101101
# Rich Utils
102-
'ArgumentDefaultsCmd2HelpFormatter',
103-
'Cmd2HelpFormatter',
104-
'get_theme',
105-
'MetavarTypeCmd2HelpFormatter',
106-
'RawDescriptionCmd2HelpFormatter',
107-
'RawTextCmd2HelpFormatter',
108-
'RichPrintKwargs',
109-
'set_theme',
110-
'TextGroup',
102+
"ArgumentDefaultsCmd2HelpFormatter",
103+
"Cmd2HelpFormatter",
104+
"get_theme",
105+
"MetavarTypeCmd2HelpFormatter",
106+
"RawDescriptionCmd2HelpFormatter",
107+
"RawTextCmd2HelpFormatter",
108+
"RichPrintKwargs",
109+
"set_theme",
110+
"TextGroup",
111111
# String Utils
112-
'stylize',
112+
"stylize",
113113
# Styles,
114-
'Cmd2Style',
114+
"Cmd2Style",
115115
# Utilities
116-
'categorize',
117-
'CustomCompletionSettings',
118-
'Settable',
119-
'set_default_str_sort_key',
116+
"categorize",
117+
"CustomCompletionSettings",
118+
"Settable",
119+
"set_default_str_sort_key",
120120
]

cmd2/argparse_completer.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@
4646

4747
# Name of the choice/completer function argument that, if present, will be passed a dictionary of
4848
# command line tokens up through the token being completed mapped to their argparse destination name.
49-
ARG_TOKENS = 'arg_tokens'
49+
ARG_TOKENS = "arg_tokens"
5050

5151

5252
def _build_hint(parser: Cmd2ArgumentParser, arg_action: argparse.Action) -> str:
5353
"""Build completion hint for a given argument."""
5454
# Check if hinting is disabled for this argument
5555
suppress_hint = arg_action.get_suppress_tab_hint() # type: ignore[attr-defined]
5656
if suppress_hint or arg_action.help == argparse.SUPPRESS:
57-
return ''
57+
return ""
5858

5959
# Use the parser's help formatter to display just this action's help text
6060
formatter = parser._get_formatter()
@@ -90,7 +90,7 @@ def _looks_like_flag(token: str, parser: Cmd2ArgumentParser) -> bool:
9090
return False
9191

9292
# Flags can't have a space
93-
return ' ' not in token
93+
return " " not in token
9494

9595

9696
class _ArgumentState:
@@ -133,8 +133,8 @@ def __init__(self, flag_arg_state: _ArgumentState) -> None:
133133
134134
:param flag_arg_state: information about the unfinished flag action.
135135
"""
136-
arg = f'{argparse._get_action_name(flag_arg_state.action)}'
137-
err = f'{build_range_error(flag_arg_state.min, flag_arg_state.max)}'
136+
arg = f"{argparse._get_action_name(flag_arg_state.action)}"
137+
err = f"{build_range_error(flag_arg_state.min, flag_arg_state.max)}"
138138
error = f"Error: argument {arg}: {err} ({flag_arg_state.count} entered)"
139139
super().__init__(error)
140140

@@ -158,7 +158,7 @@ class ArgparseCompleter:
158158
def __init__(
159159
self,
160160
parser: Cmd2ArgumentParser,
161-
cmd2_app: 'Cmd',
161+
cmd2_app: "Cmd",
162162
*,
163163
parent_tokens: Mapping[str, MutableSequence[str]] | None = None,
164164
) -> None:
@@ -269,14 +269,14 @@ def consume_argument(arg_state: _ArgumentState, arg_token: str) -> None:
269269

270270
# If we're in a flag REMAINDER arg, force all future tokens to go to that until a double dash is hit
271271
if flag_arg_state is not None and flag_arg_state.is_remainder:
272-
if token == '--': # noqa: S105
272+
if token == "--": # noqa: S105
273273
flag_arg_state = None
274274
else:
275275
consume_argument(flag_arg_state, token)
276276
continue
277277

278278
# Handle '--' which tells argparse all remaining arguments are non-flags
279-
if token == '--' and not skip_remaining_flags: # noqa: S105
279+
if token == "--" and not skip_remaining_flags: # noqa: S105
280280
# Check if there is an unfinished flag
281281
if (
282282
flag_arg_state is not None
@@ -437,8 +437,8 @@ def _update_mutex_groups(
437437
if arg_action == completer_action:
438438
return
439439

440-
arg_str = f'{argparse._get_action_name(arg_action)}'
441-
completer_str = f'{argparse._get_action_name(completer_action)}'
440+
arg_str = f"{argparse._get_action_name(arg_action)}"
441+
completer_str = f"{argparse._get_action_name(completer_action)}"
442442
error = f"Error: argument {arg_str}: not allowed with argument {completer_str}"
443443
raise CompletionError(error)
444444

@@ -566,18 +566,18 @@ def _complete_flags(self, text: str, line: str, begidx: int, endidx: int, used_f
566566
# For completion suggestions, group matched flags by action
567567
items: list[CompletionItem] = []
568568
for action, option_strings in matched_actions.items():
569-
flag_text = ', '.join(option_strings)
569+
flag_text = ", ".join(option_strings)
570570

571571
# Mark optional flags with brackets
572572
if not action.required:
573-
flag_text = '[' + flag_text + ']'
573+
flag_text = "[" + flag_text + "]"
574574

575575
# Use the first option string as the completion result for this action
576576
items.append(
577577
CompletionItem(
578578
option_strings[0],
579579
display=flag_text,
580-
display_meta=action.help or '',
580+
display_meta=action.help or "",
581581
)
582582
)
583583

@@ -720,10 +720,10 @@ def _choices_to_items(self, arg_state: _ArgumentState) -> list[CompletionItem]:
720720
for action in arg_state.action._choices_actions:
721721
if action.dest in arg_state.action.choices:
722722
subparser = arg_state.action.choices[action.dest]
723-
parser_help[subparser] = action.help or ''
723+
parser_help[subparser] = action.help or ""
724724

725725
return [
726-
CompletionItem(name, display_meta=parser_help.get(subparser, ''))
726+
CompletionItem(name, display_meta=parser_help.get(subparser, ""))
727727
for name, subparser in arg_state.action.choices.items()
728728
]
729729

cmd2/argparse_utils.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,10 @@ def build_range_error(range_min: int, range_max: float) -> str:
262262
err_msg = "expected "
263263

264264
if range_max == constants.INFINITY:
265-
plural = '' if range_min == 1 else 's'
265+
plural = "" if range_min == 1 else "s"
266266
err_msg += f"at least {range_min}"
267267
else:
268-
plural = '' if range_max == 1 else 's'
268+
plural = "" if range_max == 1 else "s"
269269
if range_min == range_max:
270270
err_msg += f"{range_min}"
271271
else:
@@ -309,8 +309,8 @@ def register_argparse_argument_parameter(
309309
raise KeyError(f"'{param_name}' conflicts with an existing attribute on argparse.Action")
310310

311311
# Check if accessors already exist (e.g., from manual patching or previous registration)
312-
getter_name = f'get_{param_name}'
313-
setter_name = f'set_{param_name}'
312+
getter_name = f"get_{param_name}"
313+
setter_name = f"set_{param_name}"
314314
if hasattr(argparse.Action, getter_name) or hasattr(argparse.Action, setter_name):
315315
raise KeyError(f"Accessor methods for '{param_name}' already exist on argparse.Action")
316316

@@ -355,11 +355,11 @@ def _validate_completion_callable(self: argparse.Action, value: Any) -> Any:
355355

356356
# Add new attributes to argparse.Action.
357357
# See _ActionsContainer_add_argument() for details on these attributes.
358-
register_argparse_argument_parameter('choices_provider', validator=_validate_completion_callable)
359-
register_argparse_argument_parameter('completer', validator=_validate_completion_callable)
360-
register_argparse_argument_parameter('table_columns')
361-
register_argparse_argument_parameter('nargs_range')
362-
register_argparse_argument_parameter('suppress_tab_hint')
358+
register_argparse_argument_parameter("choices_provider", validator=_validate_completion_callable)
359+
register_argparse_argument_parameter("completer", validator=_validate_completion_callable)
360+
register_argparse_argument_parameter("table_columns")
361+
register_argparse_argument_parameter("nargs_range")
362+
register_argparse_argument_parameter("suppress_tab_hint")
363363

364364

365365
############################################################################################################
@@ -431,11 +431,11 @@ def _ActionsContainer_add_argument( # noqa: N802
431431
or not isinstance(nargs[0], int)
432432
or not (isinstance(nargs[1], int) or nargs[1] == constants.INFINITY)
433433
):
434-
raise ValueError('Ranged values for nargs must be a tuple of 1 or 2 integers')
434+
raise ValueError("Ranged values for nargs must be a tuple of 1 or 2 integers")
435435
if nargs[0] >= nargs[1]:
436-
raise ValueError('Invalid nargs range. The first value must be less than the second')
436+
raise ValueError("Invalid nargs range. The first value must be less than the second")
437437
if nargs[0] < 0:
438-
raise ValueError('Negative numbers are invalid for nargs range')
438+
raise ValueError("Negative numbers are invalid for nargs range")
439439

440440
# Save the nargs tuple as our range setting
441441
nargs_range = nargs
@@ -465,7 +465,7 @@ def _ActionsContainer_add_argument( # noqa: N802
465465
nargs_adjusted = nargs
466466

467467
# Add the argparse-recognized version of nargs to kwargs
468-
kwargs['nargs'] = nargs_adjusted
468+
kwargs["nargs"] = nargs_adjusted
469469

470470
# Extract registered custom keyword arguments
471471
custom_attribs = {keyword: value for keyword, value in kwargs.items() if keyword in _CUSTOM_ACTION_ATTRIBS}
@@ -484,7 +484,7 @@ def _ActionsContainer_add_argument( # noqa: N802
484484

485485
# Set other registered custom attributes
486486
for keyword, value in custom_attribs.items():
487-
attr_setter = getattr(new_arg, f'set_{keyword}', None)
487+
attr_setter = getattr(new_arg, f"set_{keyword}", None)
488488
if attr_setter is not None:
489489
attr_setter(value)
490490

@@ -506,17 +506,17 @@ def __init__(
506506
epilog: RenderableType | None = None,
507507
parents: Sequence[argparse.ArgumentParser] = (),
508508
formatter_class: type[Cmd2HelpFormatter] = Cmd2HelpFormatter,
509-
prefix_chars: str = '-',
509+
prefix_chars: str = "-",
510510
fromfile_prefix_chars: str | None = None,
511511
argument_default: str | None = None,
512-
conflict_handler: str = 'error',
512+
conflict_handler: str = "error",
513513
add_help: bool = True,
514514
allow_abbrev: bool = True,
515515
exit_on_error: bool = True,
516516
suggest_on_error: bool = False,
517517
color: bool = False,
518518
*,
519-
ap_completer_type: type['ArgparseCompleter'] | None = None,
519+
ap_completer_type: type["ArgparseCompleter"] | None = None,
520520
) -> None:
521521
"""Initialize the Cmd2ArgumentParser instance.
522522
@@ -651,7 +651,7 @@ def update_prog(self, prog: str) -> None:
651651
subcmd_parser.update_prog(subcmd_prog)
652652
updated_parsers.add(subcmd_parser)
653653

654-
def _find_parser(self, subcommand_path: Iterable[str]) -> 'Cmd2ArgumentParser':
654+
def _find_parser(self, subcommand_path: Iterable[str]) -> "Cmd2ArgumentParser":
655655
"""Find a parser in the hierarchy based on a sequence of subcommand names.
656656
657657
:param subcommand_path: sequence of subcommand names leading to the target parser
@@ -670,7 +670,7 @@ def attach_subcommand(
670670
self,
671671
subcommand_path: Iterable[str],
672672
subcommand: str,
673-
subcommand_parser: 'Cmd2ArgumentParser',
673+
subcommand_parser: "Cmd2ArgumentParser",
674674
**add_parser_kwargs: Any,
675675
) -> None:
676676
"""Attach a parser as a subcommand to a command at the specified path.
@@ -719,7 +719,7 @@ def attach_subcommand(
719719
for alias in add_parser_kwargs.get("aliases", ()):
720720
subparsers_action._name_parser_map[alias] = subcommand_parser
721721

722-
def detach_subcommand(self, subcommand_path: Iterable[str], subcommand: str) -> 'Cmd2ArgumentParser':
722+
def detach_subcommand(self, subcommand_path: Iterable[str], subcommand: str) -> "Cmd2ArgumentParser":
723723
"""Detach a subcommand from a command at the specified path.
724724
725725
:param subcommand_path: sequence of subcommand names leading to the parser hosting the
@@ -753,13 +753,13 @@ def detach_subcommand(self, subcommand_path: Iterable[str], subcommand: str) ->
753753

754754
def error(self, message: str) -> NoReturn:
755755
"""Override that applies custom formatting to the error message."""
756-
lines = message.split('\n')
757-
formatted_message = ''
756+
lines = message.split("\n")
757+
formatted_message = ""
758758
for linum, line in enumerate(lines):
759759
if linum == 0:
760-
formatted_message = 'Error: ' + line
760+
formatted_message = "Error: " + line
761761
else:
762-
formatted_message += '\n ' + line
762+
formatted_message += "\n " + line
763763

764764
self.print_usage(sys.stderr)
765765

@@ -769,27 +769,27 @@ def error(self, message: str) -> NoReturn:
769769
console.print(formatted_message, style=Cmd2Style.ERROR)
770770
formatted_message = f"{capture.get()}"
771771

772-
self.exit(2, f'{formatted_message}\n')
772+
self.exit(2, f"{formatted_message}\n")
773773

774774
def _get_formatter(self, **kwargs: Any) -> Cmd2HelpFormatter:
775775
"""Override with customizations for Cmd2HelpFormatter."""
776776
return cast(Cmd2HelpFormatter, super()._get_formatter(**kwargs))
777777

778778
def format_help(self) -> str:
779779
"""Override to add a newline."""
780-
return super().format_help() + '\n'
780+
return super().format_help() + "\n"
781781

782782
def _get_nargs_pattern(self, action: argparse.Action) -> str:
783783
"""Override to support nargs ranges."""
784784
nargs_range = action.get_nargs_range() # type: ignore[attr-defined]
785785
if nargs_range:
786-
range_max = '' if nargs_range[1] == constants.INFINITY else nargs_range[1]
787-
nargs_pattern = f'(-*A{{{nargs_range[0]},{range_max}}}-*)'
786+
range_max = "" if nargs_range[1] == constants.INFINITY else nargs_range[1]
787+
nargs_pattern = f"(-*A{{{nargs_range[0]},{range_max}}}-*)"
788788

789789
# if this is an optional action, -- is not allowed
790790
if action.option_strings:
791-
nargs_pattern = nargs_pattern.replace('-*', '')
792-
nargs_pattern = nargs_pattern.replace('-', '')
791+
nargs_pattern = nargs_pattern.replace("-*", "")
792+
nargs_pattern = nargs_pattern.replace("-", "")
793793
return nargs_pattern
794794

795795
return super()._get_nargs_pattern(action)
@@ -823,8 +823,8 @@ def _check_value(self, action: argparse.Action, value: Any) -> None:
823823
if action.choices is not None and value not in action.choices:
824824
# If any choice is a CompletionItem, then display its value property.
825825
choices = [c.value if isinstance(c, CompletionItem) else c for c in action.choices]
826-
args = {'value': value, 'choices': ', '.join(map(repr, choices))}
827-
msg = _('invalid choice: %(value)r (choose from %(choices)s)')
826+
args = {"value": value, "choices": ", ".join(map(repr, choices))}
827+
msg = _("invalid choice: %(value)r (choose from %(choices)s)")
828828
raise ArgumentError(action, msg % args)
829829

830830

0 commit comments

Comments
 (0)