Skip to content

Commit 52ea5e4

Browse files
committed
Made more methods protected
1 parent e538d1a commit 52ea5e4

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

cmd2/cmd2.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,7 @@ def _complete_statement(self, line: str) -> Statement:
18371837
# - a multiline command with unclosed quotation marks
18381838
try:
18391839
self._at_continuation_prompt = True
1840-
newline = self.pseudo_raw_input(self.continuation_prompt)
1840+
newline = self._pseudo_raw_input(self.continuation_prompt)
18411841
if newline == 'eof':
18421842
# they entered either a blank line, or we hit an EOF
18431843
# for some other reason. Turn the literal 'eof'
@@ -2137,7 +2137,7 @@ def default(self, statement: Statement) -> Optional[bool]:
21372137
err_msg = self.default_error.format(statement.command)
21382138
self._decolorized_write(sys.stderr, "{}\n".format(err_msg))
21392139

2140-
def pseudo_raw_input(self, prompt: str) -> str:
2140+
def _pseudo_raw_input(self, prompt: str) -> str:
21412141
"""Began life as a copy of cmd's cmdloop; like raw_input but
21422142
21432143
- accounts for changed stdin, stdout
@@ -2232,7 +2232,7 @@ def _cmdloop(self) -> None:
22322232
while not stop:
22332233
# Get commands from user
22342234
try:
2235-
line = self.pseudo_raw_input(self.prompt)
2235+
line = self._pseudo_raw_input(self.prompt)
22362236
except KeyboardInterrupt as ex:
22372237
if self.quit_on_sigint:
22382238
raise ex
@@ -2258,7 +2258,7 @@ def _cmdloop(self) -> None:
22582258

22592259
# ----- Alias sub-command functions -----
22602260

2261-
def alias_create(self, args: argparse.Namespace) -> None:
2261+
def _alias_create(self, args: argparse.Namespace) -> None:
22622262
"""Create or overwrite an alias"""
22632263

22642264
# Validate the alias name
@@ -2286,7 +2286,7 @@ def alias_create(self, args: argparse.Namespace) -> None:
22862286
self.aliases[args.name] = value
22872287
self.poutput("Alias '{}' {}".format(args.name, result))
22882288

2289-
def alias_delete(self, args: argparse.Namespace) -> None:
2289+
def _alias_delete(self, args: argparse.Namespace) -> None:
22902290
"""Delete aliases"""
22912291
if args.all:
22922292
self.aliases.clear()
@@ -2301,7 +2301,7 @@ def alias_delete(self, args: argparse.Namespace) -> None:
23012301
else:
23022302
self.perror("Alias '{}' does not exist".format(cur_name), traceback_war=False)
23032303

2304-
def alias_list(self, args: argparse.Namespace) -> None:
2304+
def _alias_list(self, args: argparse.Namespace) -> None:
23052305
"""List some or all aliases"""
23062306
if args.name:
23072307
for cur_name in utils.remove_duplicates(args.name):
@@ -2350,7 +2350,7 @@ def alias_list(self, args: argparse.Namespace) -> None:
23502350
setattr(alias_create_parser.add_argument('command_args', nargs=argparse.REMAINDER,
23512351
help='arguments to pass to command'),
23522352
ACTION_ARG_CHOICES, ('path_complete',))
2353-
alias_create_parser.set_defaults(func=alias_create)
2353+
alias_create_parser.set_defaults(func=_alias_create)
23542354

23552355
# alias -> delete
23562356
alias_delete_help = "delete aliases"
@@ -2360,7 +2360,7 @@ def alias_list(self, args: argparse.Namespace) -> None:
23602360
setattr(alias_delete_parser.add_argument('name', nargs='*', help='alias to delete'),
23612361
ACTION_ARG_CHOICES, get_alias_names)
23622362
alias_delete_parser.add_argument('-a', '--all', action='store_true', help="delete all aliases")
2363-
alias_delete_parser.set_defaults(func=alias_delete)
2363+
alias_delete_parser.set_defaults(func=_alias_delete)
23642364

23652365
# alias -> list
23662366
alias_list_help = "list aliases"
@@ -2373,7 +2373,7 @@ def alias_list(self, args: argparse.Namespace) -> None:
23732373
description=alias_list_description)
23742374
setattr(alias_list_parser.add_argument('name', nargs="*", help='alias to list'),
23752375
ACTION_ARG_CHOICES, get_alias_names)
2376-
alias_list_parser.set_defaults(func=alias_list)
2376+
alias_list_parser.set_defaults(func=_alias_list)
23772377

23782378
# Preserve quotes since we are passing strings to other commands
23792379
@with_argparser(alias_parser, preserve_quotes=True)
@@ -2389,7 +2389,7 @@ def do_alias(self, args: argparse.Namespace) -> None:
23892389

23902390
# ----- Macro sub-command functions -----
23912391

2392-
def macro_create(self, args: argparse.Namespace) -> None:
2392+
def _macro_create(self, args: argparse.Namespace) -> None:
23932393
"""Create or overwrite a macro"""
23942394

23952395
# Validate the macro name
@@ -2467,7 +2467,7 @@ def macro_create(self, args: argparse.Namespace) -> None:
24672467
self.macros[args.name] = Macro(name=args.name, value=value, minimum_arg_count=max_arg_num, arg_list=arg_list)
24682468
self.poutput("Macro '{}' {}".format(args.name, result))
24692469

2470-
def macro_delete(self, args: argparse.Namespace) -> None:
2470+
def _macro_delete(self, args: argparse.Namespace) -> None:
24712471
"""Delete macros"""
24722472
if args.all:
24732473
self.macros.clear()
@@ -2482,7 +2482,7 @@ def macro_delete(self, args: argparse.Namespace) -> None:
24822482
else:
24832483
self.perror("Macro '{}' does not exist".format(cur_name), traceback_war=False)
24842484

2485-
def macro_list(self, args: argparse.Namespace) -> None:
2485+
def _macro_list(self, args: argparse.Namespace) -> None:
24862486
"""List some or all macros"""
24872487
if args.name:
24882488
for cur_name in utils.remove_duplicates(args.name):
@@ -2554,7 +2554,7 @@ def macro_list(self, args: argparse.Namespace) -> None:
25542554
setattr(macro_create_parser.add_argument('command_args', nargs=argparse.REMAINDER,
25552555
help='arguments to pass to command'),
25562556
ACTION_ARG_CHOICES, ('path_complete',))
2557-
macro_create_parser.set_defaults(func=macro_create)
2557+
macro_create_parser.set_defaults(func=_macro_create)
25582558

25592559
# macro -> delete
25602560
macro_delete_help = "delete macros"
@@ -2564,7 +2564,7 @@ def macro_list(self, args: argparse.Namespace) -> None:
25642564
setattr(macro_delete_parser.add_argument('name', nargs='*', help='macro to delete'),
25652565
ACTION_ARG_CHOICES, get_macro_names)
25662566
macro_delete_parser.add_argument('-a', '--all', action='store_true', help="delete all macros")
2567-
macro_delete_parser.set_defaults(func=macro_delete)
2567+
macro_delete_parser.set_defaults(func=_macro_delete)
25682568

25692569
# macro -> list
25702570
macro_list_help = "list macros"
@@ -2576,7 +2576,7 @@ def macro_list(self, args: argparse.Namespace) -> None:
25762576
macro_list_parser = macro_subparsers.add_parser('list', help=macro_list_help, description=macro_list_description)
25772577
setattr(macro_list_parser.add_argument('name', nargs="*", help='macro to list'),
25782578
ACTION_ARG_CHOICES, get_macro_names)
2579-
macro_list_parser.set_defaults(func=macro_list)
2579+
macro_list_parser.set_defaults(func=_macro_list)
25802580

25812581
# Preserve quotes since we are passing strings to other commands
25822582
@with_argparser(macro_parser, preserve_quotes=True)
@@ -2862,7 +2862,7 @@ def select(self, opts: Union[str, List[str], List[Tuple[Any, Optional[str]]]],
28622862
len(fulloptions)))
28632863
return result
28642864

2865-
def cmdenvironment(self) -> str:
2865+
def _cmdenvironment(self) -> str:
28662866
"""Get a summary report of read-only settings which the user cannot modify at runtime.
28672867
28682868
:return: summary report of read-only settings which the user cannot modify at runtime
@@ -2872,7 +2872,7 @@ def cmdenvironment(self) -> str:
28722872
Output redirection and pipes allowed: {}"""
28732873
return read_only_settings.format(str(self._statement_parser.terminators), self.allow_redirection)
28742874

2875-
def show(self, args: argparse.Namespace, parameter: str = '') -> None:
2875+
def _show(self, args: argparse.Namespace, parameter: str = '') -> None:
28762876
"""Shows current settings of parameters.
28772877
28782878
:param args: argparse parsed arguments from the set command
@@ -2896,7 +2896,7 @@ def show(self, args: argparse.Namespace, parameter: str = '') -> None:
28962896

28972897
# If user has requested to see all settings, also show read-only settings
28982898
if args.all:
2899-
self.poutput('\nRead only settings:{}'.format(self.cmdenvironment()))
2899+
self.poutput('\nRead only settings:{}'.format(self._cmdenvironment()))
29002900
else:
29012901
self.perror("Parameter '{}' not supported (type 'set' for list of parameters).".format(param),
29022902
traceback_war=False)
@@ -2919,12 +2919,12 @@ def do_set(self, args: argparse.Namespace) -> None:
29192919

29202920
# Check if param was passed in
29212921
if not args.param:
2922-
return self.show(args)
2922+
return self._show(args)
29232923
param = utils.norm_fold(args.param.strip())
29242924

29252925
# Check if value was passed in
29262926
if not args.value:
2927-
return self.show(args, param)
2927+
return self._show(args, param)
29282928
value = args.value
29292929

29302930
# Check if param points to just one settable
@@ -2933,7 +2933,7 @@ def do_set(self, args: argparse.Namespace) -> None:
29332933
if len(hits) == 1:
29342934
param = hits[0]
29352935
else:
2936-
return self.show(args, param)
2936+
return self._show(args, param)
29372937

29382938
# Update the settable's value
29392939
current_value = getattr(self, param)
@@ -3700,7 +3700,7 @@ def do__relative_run_script(self, args: argparse.Namespace) -> Optional[bool]:
37003700
# _relative_load has been deprecated
37013701
do__relative_load = do__relative_run_script
37023702

3703-
def run_transcript_tests(self, transcript_paths: List[str]) -> None:
3703+
def _run_transcript_tests(self, transcript_paths: List[str]) -> None:
37043704
"""Runs transcript tests for provided file(s).
37053705
37063706
This is called when either -t is provided on the command line or the transcript_files argument is provided
@@ -4020,7 +4020,7 @@ def cmdloop(self, intro: Optional[str] = None) -> int:
40204020

40214021
# If transcript-based regression testing was requested, then do that instead of the main loop
40224022
if self._transcript_files is not None:
4023-
self.run_transcript_tests([os.path.expanduser(tf) for tf in self._transcript_files])
4023+
self._run_transcript_tests([os.path.expanduser(tf) for tf in self._transcript_files])
40244024
else:
40254025
# If an intro was supplied in the method call, allow it to override the default
40264026
if intro is not None:

tests/test_cmd2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ def test_raw_input(base_app):
14681468
m = mock.Mock(name='input', return_value=fake_input)
14691469
builtins.input = m
14701470

1471-
line = base_app.pseudo_raw_input('(cmd2)')
1471+
line = base_app._pseudo_raw_input('(cmd2)')
14721472
assert line == fake_input
14731473

14741474
def test_stdin_input():
@@ -1480,7 +1480,7 @@ def test_stdin_input():
14801480
m = mock.Mock(name='readline', return_value=fake_input)
14811481
app.stdin.readline = m
14821482

1483-
line = app.pseudo_raw_input('(cmd2)')
1483+
line = app._pseudo_raw_input('(cmd2)')
14841484
assert line == fake_input
14851485

14861486
def test_empty_stdin_input():
@@ -1492,7 +1492,7 @@ def test_empty_stdin_input():
14921492
m = mock.Mock(name='readline', return_value=fake_input)
14931493
app.stdin.readline = m
14941494

1495-
line = app.pseudo_raw_input('(cmd2)')
1495+
line = app._pseudo_raw_input('(cmd2)')
14961496
assert line == 'eof'
14971497

14981498
def test_poutput_string(outsim_app):

0 commit comments

Comments
 (0)