summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-07-19 10:06:19 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-07-19 10:06:19 -0400
commit920a9faa050441fbe064eed200f74dbdc0ba9663 (patch)
tree8c9007dd44d5d3e1ef5a5171783acbc606f2ca29 /examples
parent128d94accb0a6a8ab7197d26dab2cdafd83a1922 (diff)
downloadcmd2-git-920a9faa050441fbe064eed200f74dbdc0ba9663.tar.gz
Changed all uses of sub-command to subcommand
Diffstat (limited to 'examples')
-rw-r--r--examples/scripts/save_help_text.py12
-rwxr-xr-xexamples/subcommands.py42
-rwxr-xr-xexamples/tab_autocompletion.py4
-rwxr-xr-xexamples/tab_completion.py2
4 files changed, 30 insertions, 30 deletions
diff --git a/examples/scripts/save_help_text.py b/examples/scripts/save_help_text.py
index a68b0ad9..12d66d6d 100644
--- a/examples/scripts/save_help_text.py
+++ b/examples/scripts/save_help_text.py
@@ -1,7 +1,7 @@
# coding=utf-8
# flake8: noqa F821
"""
-A cmd2 script that saves the help text for every command, sub-command, and topic to a file.
+A cmd2 script that saves the help text for every command, subcommand, and topic to a file.
This is meant to be run within a cmd2 session using run_pyscript.
"""
@@ -14,19 +14,19 @@ ASTERISKS = "********************************************************"
def get_sub_commands(parser: argparse.ArgumentParser) -> List[str]:
- """Get a list of sub-commands for an ArgumentParser"""
+ """Get a list of subcommands for an ArgumentParser"""
sub_cmds = []
- # Check if this is parser has sub-commands
+ # Check if this is parser has subcommands
if parser is not None and parser._subparsers is not None:
- # Find the _SubParsersAction for the sub-commands of this parser
+ # Find the _SubParsersAction for the subcommands of this parser
for action in parser._subparsers._actions:
if isinstance(action, argparse._SubParsersAction):
for sub_cmd, sub_cmd_parser in action.choices.items():
sub_cmds.append(sub_cmd)
- # Look for nested sub-commands
+ # Look for nested subcommands
for nested_sub_cmd in get_sub_commands(sub_cmd_parser):
sub_cmds.append('{} {}'.format(sub_cmd, nested_sub_cmd))
@@ -94,7 +94,7 @@ def main() -> None:
add_help_to_file(item, outfile, is_command)
if is_command:
- # Add any sub-commands
+ # Add any subcommands
for subcmd in get_sub_commands(getattr(self.cmd_func(item), 'argparser', None)):
full_cmd = '{} {}'.format(item, subcmd)
add_help_to_file(full_cmd, outfile, is_command)
diff --git a/examples/subcommands.py b/examples/subcommands.py
index 89bcaf85..0b228e79 100755
--- a/examples/subcommands.py
+++ b/examples/subcommands.py
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
# coding=utf-8
-"""A simple example demonstrating how to use Argparse to support sub-commands.
+"""A simple example demonstrating how to use Argparse to support subcommands.
-This example shows an easy way for a single command to have many sub-commands, each of which takes different arguments
+This example shows an easy way for a single command to have many subcommands, each of which takes different arguments
and provides separate contextual help.
"""
import argparse
@@ -13,15 +13,15 @@ sport_item_strs = ['Bat', 'Basket', 'Basketball', 'Football', 'Space Ball']
# create the top-level parser for the base command
base_parser = argparse.ArgumentParser(prog='base')
-base_subparsers = base_parser.add_subparsers(title='sub-commands', help='sub-command help')
+base_subparsers = base_parser.add_subparsers(title='subcommands', help='subcommand help')
-# create the parser for the "foo" sub-command
+# create the parser for the "foo" subcommand
parser_foo = base_subparsers.add_parser('foo', help='foo help')
parser_foo.add_argument('-x', type=int, default=1, help='integer')
parser_foo.add_argument('y', type=float, help='float')
parser_foo.add_argument('input_file', type=str, help='Input File')
-# create the parser for the "bar" sub-command
+# create the parser for the "bar" subcommand
parser_bar = base_subparsers.add_parser('bar', help='bar help')
bar_subparsers = parser_bar.add_subparsers(title='layer3', help='help for 3rd layer of commands')
@@ -31,7 +31,7 @@ bar_subparsers.add_parser('apple', help='apple help')
bar_subparsers.add_parser('artichoke', help='artichoke help')
bar_subparsers.add_parser('cranberries', help='cranberries help')
-# create the parser for the "sport" sub-command
+# create the parser for the "sport" subcommand
parser_sport = base_subparsers.add_parser('sport', help='sport help')
sport_arg = parser_sport.add_argument('sport', help='Enter name of a sport', choices=sport_item_strs)
@@ -39,15 +39,15 @@ sport_arg = parser_sport.add_argument('sport', help='Enter name of a sport', cho
# create the top-level parser for the alternate command
# The alternate command doesn't provide its own help flag
base2_parser = argparse.ArgumentParser(prog='alternate', add_help=False)
-base2_subparsers = base2_parser.add_subparsers(title='sub-commands', help='sub-command help')
+base2_subparsers = base2_parser.add_subparsers(title='subcommands', help='subcommand help')
-# create the parser for the "foo" sub-command
+# create the parser for the "foo" subcommand
parser_foo2 = base2_subparsers.add_parser('foo', help='foo help')
parser_foo2.add_argument('-x', type=int, default=1, help='integer')
parser_foo2.add_argument('y', type=float, help='float')
parser_foo2.add_argument('input_file', type=str, help='Input File')
-# create the parser for the "bar" sub-command
+# create the parser for the "bar" subcommand
parser_bar2 = base2_subparsers.add_parser('bar', help='bar help')
bar2_subparsers = parser_bar2.add_subparsers(title='layer3', help='help for 3rd layer of commands')
@@ -57,33 +57,33 @@ bar2_subparsers.add_parser('apple', help='apple help')
bar2_subparsers.add_parser('artichoke', help='artichoke help')
bar2_subparsers.add_parser('cranberries', help='cranberries help')
-# create the parser for the "sport" sub-command
+# create the parser for the "sport" subcommand
parser_sport2 = base2_subparsers.add_parser('sport', help='sport help')
sport2_arg = parser_sport2.add_argument('sport', help='Enter name of a sport', choices=sport_item_strs)
class SubcommandsExample(cmd2.Cmd):
"""
- Example cmd2 application where we a base command which has a couple sub-commands
- and the "sport" sub-command has tab completion enabled.
+ Example cmd2 application where we a base command which has a couple subcommands
+ and the "sport" subcommand has tab completion enabled.
"""
def __init__(self):
super().__init__()
- # sub-command functions for the base command
+ # subcommand functions for the base command
def base_foo(self, args):
- """foo sub-command of base command"""
+ """foo subcommand of base command"""
self.poutput(args.x * args.y)
def base_bar(self, args):
- """bar sub-command of base command"""
+ """bar subcommand of base command"""
self.poutput('((%s))' % args.z)
def base_sport(self, args):
- """sport sub-command of base command"""
+ """sport subcommand of base command"""
self.poutput('Sport is {}'.format(args.sport))
- # Set handler functions for the sub-commands
+ # Set handler functions for the subcommands
parser_foo.set_defaults(func=base_foo)
parser_bar.set_defaults(func=base_bar)
parser_sport.set_defaults(func=base_sport)
@@ -93,10 +93,10 @@ class SubcommandsExample(cmd2.Cmd):
"""Base command help"""
func = getattr(args, 'func', None)
if func is not None:
- # Call whatever sub-command function was selected
+ # Call whatever subcommand function was selected
func(self, args)
else:
- # No sub-command was provided, so call help
+ # No subcommand was provided, so call help
self.do_help('base')
@cmd2.with_argparser(base2_parser)
@@ -104,10 +104,10 @@ class SubcommandsExample(cmd2.Cmd):
"""Alternate command help"""
func = getattr(args, 'func', None)
if func is not None:
- # Call whatever sub-command function was selected
+ # Call whatever subcommand function was selected
func(self, args)
else:
- # No sub-command was provided, so call help
+ # No subcommand was provided, so call help
self.do_help('alternate')
diff --git a/examples/tab_autocompletion.py b/examples/tab_autocompletion.py
index 7ab827e5..2142fe2e 100755
--- a/examples/tab_autocompletion.py
+++ b/examples/tab_autocompletion.py
@@ -22,7 +22,7 @@ def query_actors() -> List[str]:
class TabCompleteExample(cmd2.Cmd):
- """ Example cmd2 application where we a base command which has a couple sub-commands."""
+ """ Example cmd2 application where we a base command which has a couple subcommands."""
CAT_AUTOCOMPLETE = 'AutoComplete Examples'
@@ -252,7 +252,7 @@ class TabCompleteExample(cmd2.Cmd):
@cmd2.with_category(CAT_AUTOCOMPLETE)
@cmd2.with_argparser(video_parser)
def do_video(self, args):
- """Video management command demonstrates multiple layers of sub-commands being handled by AutoCompleter"""
+ """Video management command demonstrates multiple layers of subcommands being handled by AutoCompleter"""
func = getattr(args, 'func', None)
if func is not None:
# Call whatever subcommand function was selected
diff --git a/examples/tab_completion.py b/examples/tab_completion.py
index 2830b002..1a25238f 100755
--- a/examples/tab_completion.py
+++ b/examples/tab_completion.py
@@ -14,7 +14,7 @@ sport_item_strs = ['Bat', 'Basket', 'Basketball', 'Football', 'Space Ball']
class TabCompleteExample(cmd2.Cmd):
- """ Example cmd2 application where we a base command which has a couple sub-commands."""
+ """ Example cmd2 application where we a base command which has a couple subcommands."""
def __init__(self):
super().__init__()