Skip to content

Commit 89f58e2

Browse files
authored
Merge pull request #133 from python-cmd2/simplify_help
Removed some help_* methods
2 parents 3893119 + 137f8df commit 89f58e2

File tree

1 file changed

+21
-105
lines changed

1 file changed

+21
-105
lines changed

cmd2.py

Lines changed: 21 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,36 +1315,16 @@ def do_set(self, arg):
13151315
def do_pause(self, text):
13161316
"""Displays the specified text then waits for the user to press <Enter>.
13171317
1318-
Usage: pause [text]
1319-
1320-
:param text: str - Text to display to the user (default: blank line)
1321-
"""
1322-
sm.input(text + '\n')
1323-
1324-
def help_pause(self):
1325-
"""Print help for do_pause()."""
1326-
help_str = """Displays the specified text then waits for the user to press <Enter>.
1327-
13281318
Usage: pause [text]"""
1329-
self.stdout.write("{}\n".format(help_str))
1319+
sm.input(text + '\n')
13301320

13311321
# noinspection PyMethodMayBeStatic
13321322
def do_shell(self, command):
13331323
"""Execute a command as if at the OS prompt.
13341324
1335-
Usage: shell command
1336-
1337-
:param command: str - shell command to execute
1338-
"""
1325+
Usage: shell <command> [arguments]"""
13391326
os.system(command)
13401327

1341-
def help_shell(self):
1342-
"""Print help for do_shell()."""
1343-
help_str = """Execute a command as if at the OS prompt.
1344-
1345-
Usage: shell cmd"""
1346-
self.stdout.write("{}\n".format(help_str))
1347-
13481328
def path_complete(self, text, line, begidx, endidx, dir_exe_only=False, dir_only=False):
13491329
"""Method called to complete an input line by local file system path completion.
13501330
@@ -1710,23 +1690,20 @@ def _last_matching(self, arg):
17101690
def do_edit(self, arg):
17111691
"""Edit a file or command in a text editor.
17121692
1713-
Usage: edit [N]|[file_path]
1714-
1715-
:param arg: str - [N]|[file_path]
1693+
Usage: edit [N]|[file_path]
17161694
1717-
* **N** - Number of command (from history), or `*` for all commands in history (default: most recent command)
1718-
* **file_path** - path to a file to open in editor
1695+
* N - Number of command (from history), or `*` for all commands in history (default: last command)
1696+
* file_path - path to a file to open in editor
17191697
1720-
The editor used is determined by the ``editor`` settable parameter.
1721-
"set editor (program-name)" to change or set the EDITOR environment variable.
1698+
The editor used is determined by the ``editor`` settable parameter.
1699+
"set editor (program-name)" to change or set the EDITOR environment variable.
17221700
1723-
The optional arguments are mutually exclusive. Either a command number OR a file name can be supplied.
1724-
If neither is supplied, the most recent command in the history is edited.
1701+
The optional arguments are mutually exclusive. Either a command number OR a file name can be supplied.
1702+
If neither is supplied, the most recent command in the history is edited.
17251703
1726-
Edited commands are always run after the editor is closed.
1704+
Edited commands are always run after the editor is closed.
17271705
1728-
Edited files are run on close if the ``autorun_on_edit`` settable parameter is True.
1729-
"""
1706+
Edited files are run on close if the ``autorun_on_edit`` settable parameter is True."""
17301707
if not self.editor:
17311708
raise EnvironmentError("Please use 'set editor' to specify your text editing program of choice.")
17321709
filename = self.default_file_name
@@ -1749,41 +1726,17 @@ def do_edit(self, arg):
17491726
if self.autorun_on_edit or buffer:
17501727
self.do_load(filename)
17511728

1752-
def help_edit(self):
1753-
"""Print help for do_edit()."""
1754-
help_str = """Edit a file or command in a text editor.
1755-
1756-
Usage: edit [N]|[file_path]
1757-
1758-
optional arguments:
1759-
N Number of command (from history), or `*` for all commands in history (default: most recent command)
1760-
file_path path to a file to open in editor
1761-
1762-
The editor used is determined by the `editor` settable parameter.
1763-
"set editor (program-name" to change or set the EDITOR environment variable.
1764-
1765-
The optional arguments are mutually exclusive. Either a command number OR a file name can be supplied.
1766-
If neither is supplied, the most recent command in the history is edited.
1767-
1768-
Edited commands are always run after the editor is closed.
1769-
1770-
Edited files are run on close if the `autorun_on_edit` settable parameter is True."""
1771-
self.stdout.write("{}\n".format(help_str))
1772-
17731729
saveparser = (pyparsing.Optional(pyparsing.Word(pyparsing.nums) ^ '*')("idx") +
17741730
pyparsing.Optional(pyparsing.Word(legalChars + '/\\'))("fname") +
17751731
pyparsing.stringEnd)
17761732

17771733
def do_save(self, arg):
17781734
"""Saves command(s) from history to file.
17791735
1780-
Usage: save [N] [file_path]
1781-
1782-
:param arg: str - [N] [filepath]
1736+
Usage: save [N] [file_path]
17831737
1784-
* **N** - Number of command (from history), or `*` for all commands in history (default: most recent command)
1785-
* **file_path** - location to save script of command(s) to (default: value stored in ``default_file_name``)
1786-
"""
1738+
* N - Number of command (from history), or `*` for all commands in history (default: last command)
1739+
* file_path - location to save script of command(s) to (default: value stored in `default_file_name` param)"""
17871740
try:
17881741
args = self.saveparser.parseString(arg)
17891742
except pyparsing.ParseException:
@@ -1806,17 +1759,6 @@ def do_save(self, arg):
18061759
self.perror('Error saving {}'.format(fname))
18071760
raise
18081761

1809-
def help_save(self):
1810-
"""Print help for do_save()."""
1811-
help_str = """Saves command(s) from history to file.
1812-
1813-
Usage: save [N] [file_path]
1814-
1815-
optional arguments:
1816-
N - Number of command (from history), or `*` for all commands in history (default: most recent command)
1817-
file_path - location to save script of command(s) to (default: value stored in `default_file_name` parameter)"""
1818-
self.stdout.write("{}\n".format(help_str))
1819-
18201762
def _read_file_or_url(self, fname):
18211763
"""Open a file or URL for reading by the do_load() method.
18221764
@@ -1871,12 +1813,11 @@ def do__relative_load(self, arg=None):
18711813
def do_load(self, file_path=None):
18721814
"""Runs commands in script at file or URL.
18731815
1874-
Usage: load [file_path]
1816+
Usage: load [file_path]
18751817
1876-
:param file_path: str - a file path or URL pointing to a script (default: value stored in ``default_file_name``)
1877-
:return: bool - True implies application should stop, False to continue like normal
1818+
* file_path - a file path or URL pointing to a script (default: value stored in `default_file_name` param)
18781819
1879-
Script should contain one command per line, just like command would be typed in console.
1820+
Script should contain one command per line, just like command would be typed in console.
18801821
"""
18811822
# If arg is None or arg is an empty string, use the default filename
18821823
if not file_path:
@@ -1901,42 +1842,17 @@ def do_load(self, file_path=None):
19011842
self.lastcmd = ''
19021843
return stop and (stop != self._STOP_SCRIPT_NO_EXIT)
19031844

1904-
def help_load(self):
1905-
"""Print help for do_load()."""
1906-
help_str = """Runs commands in script at file or URL.
1907-
1908-
Usage: load [file_path]
1909-
1910-
optional argument:
1911-
file_path - a file path or URL pointing to a script (default: value stored in `default_file_name` parameter)
1912-
1913-
Script should contain one command per line, just like command would be typed in console."""
1914-
self.stdout.write("{}\n".format(help_str))
1915-
19161845
def do_run(self, arg):
19171846
"""run [arg]: re-runs an earlier command
19181847
1919-
:param arg: str - determines which command is re-run, as follows:
1920-
1921-
* no arg -> run most recent command
1922-
* arg is integer -> run one history item, by index
1923-
* arg is string -> run most recent command by string search
1924-
* arg is /enclosed in forward-slashes/ -> run most recent by regex
1925-
"""
1926-
runme = self._last_matching(arg)
1927-
self.pfeedback(runme)
1928-
if runme:
1929-
return self.onecmd_plus_hooks(runme)
1930-
1931-
def help_run(self):
1932-
"""Print help for do_run()."""
1933-
help_str = """run [arg]: re-runs an earlier command
1934-
19351848
no arg -> run most recent command
19361849
arg is integer -> run one history item, by index
19371850
arg is string -> run most recent command by string search
19381851
arg is /enclosed in forward-slashes/ -> run most recent by regex"""
1939-
self.stdout.write("{}\n".format(help_str))
1852+
runme = self._last_matching(arg)
1853+
self.pfeedback(runme)
1854+
if runme:
1855+
return self.onecmd_plus_hooks(runme)
19401856

19411857
def run_transcript_tests(self, callargs):
19421858
"""Runs transcript tests for provided file(s).

0 commit comments

Comments
 (0)