summaryrefslogtreecommitdiff
path: root/examples/python_scripting.py
Commit message (Collapse)AuthorAgeFilesLines
* Updated all examples to use Cmd2ArgumentParser instead of ↵Kevin Van Brunt2021-06-171-2/+1
| | | | | | argparse.ArgumentParser. This is best practice for consistency of appearance between built-in and custom commands.
* Style changes from running black on Python 3.9Kevin Van Brunt2021-04-271-1/+1
|
* Renamed use_ipython keyword parameter of cmd2.Cmd.__init__() to include_ipy.Kevin Van Brunt2021-03-301-2/+2
| | | | | | | | | | Added include_py keyword parameter to cmd2.Cmd.__init__(). If False, then the py command will not be available. Removed ability to run Python commands from the command line with py. Made banners and exit messages of Python and IPython consistent. Changed utils.is_text_file() to raise OSError if file cannot be read.
* Add in isort changesTodd Leonhardt2021-01-311-1/+3
|
* Attempt to fix remaining black failuresTodd Leonhardt2021-01-311-2/+2
|
* Add black for automatic code formatTodd Leonhardt2021-01-311-3/+2
|
* Changed isort to force wrapping of imports to reduce merge conflicts from ↵Eric Lin2021-01-221-1/+3
| | | | minor import changes.
* Marked with_arparser_and_unknown_args deprecated and consolidatedEric Lin2020-08-041-1/+1
| | | | implementation as an option to with_argparser instead.
* Update scripting docs. Closes #765.kotfu2020-02-281-13/+19
|
* Updated python scripting exmaple to illustrate howEric Lin2020-02-241-17/+11
| | | | | stdout/stderr is automatically captured in CommandResult during python scripting. Fixes #898
* Overhauling tab completion examplesKevin Van Brunt2020-02-121-0/+1
|
* Renamed locals_in_py to self_in_pyTodd Leonhardt2020-01-271-1/+1
| | | | This more accurately reflects what it controls
* Minor update to embedded python shells docsTodd Leonhardt2019-11-031-1/+1
|
* Simplified ansi color dictionaries and lookup methodsTodd Leonhardt2019-06-271-3/+2
| | | | | | | Also: - Updated examples that use color to use cmd2.ansi instead of colorama - Updated tests that use color to use cmd2.ansi instead of colorama - plumbum_colorspy example shows how to override color lookup functions to use a different color library
* Replaced more pexcept uses with perrorKevin Van Brunt2019-06-251-3/+3
|
* Initial Commit for Issue 698xNinjaKittyx2019-06-241-3/+3
|
* Made last_result public and restored the initialization of it in __init__ ↵Todd Leonhardt2019-06-231-4/+4
| | | | and associated comment
* Updated commentKevin Van Brunt2019-06-151-4/+4
|
* Updated various documentation and tests to not use loadTodd Leonhardt2019-06-151-4/+4
|
* Updated documentationKevin Van Brunt2019-06-151-2/+2
|
* Refactor exit_code implementationTodd Leonhardt2019-05-201-1/+2
| | | | | | | | | | | | cmd2.Cmd.cmdloop() now returns self.exit_code which should be an integer Also: - Refactored examples to call sys.exit(app.cmdloop()) in their __main__ - Running transcript tests now sets the exit_code accordingly based on success/failure - Updated CHANGELOG - Updated README - Updated Sphinx docs - Added unit test for case when transcript test fails
* Refactored filtering in path_complete to use a functionKevin Van Brunt2018-10-261-1/+1
|
* Merge branch 'master' into colorizeTodd Leonhardt2018-09-251-1/+1
|\
| * Removed a Python3-only comment from an example since Python 2 is no longer ↵Todd Leonhardt2018-09-251-1/+1
| | | | | | | | supported
* | Added optional color argument to poutput() for providing a color escape code ↵Todd Leonhardt2018-09-241-1/+3
|/ | | | | | | | to colorize the output with Also: - Added optional err_color and war_color arguments to perror() for providing color escape codes - Removed usage of deprecated colorize() method within the examples
* Removed remaining type hints in docstringsKevin Van Brunt2018-09-211-4/+4
|
* Deprecated CmdResult helper class and promoted CommandResultTodd Leonhardt2018-06-231-5/+7
| | | | | | | | | | | | | | These classes are subtly different, particularly in terms of their truthiness. CmdResult - attributes: out, err, war - truthy: if err is falsy CommandResult - attributes: stdout, stderr, data - truthy: if err is falsy AND data is not None So CmdResult was oriented to provide essentially info, error, and warning messages to the user (typically as stirngs), whereas CommandResult is geared towards providing info and error messages to the user as strings in addition to data to the user in a command-specific format which is arbitrary other than it should never be None if the command succeeds.
* Fixed conditional.py scriptTodd Leonhardt2018-05-261-0/+1
| | | | | | Also: - Made self.locals_in_py = True for main.py and examples/python_scripting.py - This makes debugging easier in the embedded IPython shell provided by the opt-in ipy command
* Standardize cmd2 imports in tests and exampleskotfu2018-05-231-1/+1
|
* Removed the expensive imports from cmd2/__init__.pyEric Lin2018-04-251-1/+1
| | | | | | | Added some shared definitions to cmd2/__init__.py -> maybe there's a better place for these? Figured out how to trick bash into showing argument hints. It's a bit weird. Updated all of the tests and examples to import cmd2 resources from their new location without the automatic imports in cmd2/__init__.py For #369
* Started removing dependency on sixTodd Leonhardt2018-04-151-1/+1
| | | | | | | Removed all dependency on six other than for six.moves.input Also: - Started removing code branches which were for Python 2 support
* Addressed code review commentsKevin Van Brunt2018-03-271-3/+3
|
* Fixed python_scripting.py exampleTodd Leonhardt2018-03-011-11/+11
| | | | - Since path_complete got moved outside of cmd2.Cmd and is now a function instead of a method, need to do partial argument binding with functools.partial() instead of functools.partialmethod()
* Cleanup of documentation and examplesTodd Leonhardt2018-01-171-1/+0
| | | | Removed usage of and reference to attributes and commands which have now been removed.
* Renamed new decorator to @with_argparser_and_unknown_args to make it more ↵Todd Leonhardt2018-01-151-2/+2
| | | | descriptive
* Changed @with_argument_parser to only pass single argument to commandsTodd Leonhardt2018-01-151-8/+10
| | | | Also added another @with_argparser_and_list decorator that uses argparse.parse_known_args to pass two arguments to a command: both the argparse output and a list of unknown/unmatched args.
* Modified examples still using @options to import make_option from optparseTodd Leonhardt2018-01-151-10/+10
|
* Add screenshot to front pageTodd Leonhardt2017-07-031-1/+1
| | | | | | | Also: - Updated pythong_scripting.py example to show how to colorize text - Updated contributing.md to show how to run code coverage in parallel using python-xdist and -nauto - Updated contributing.md to talk more about looking at unit test results within the PR
* Moved example scripts from examples to examples/scripts directlyTodd Leonhardt2017-06-211-1/+1
| | | | | | Cleaned up the examples directory by adding a scripts subdirectory. This makes it a bit clearer which Python files are example cmd2 applications and which are example Python scripts for use with the pyscript command.
* Changed default value for USE_ARG_LIST global to TrueTodd Leonhardt2017-06-141-3/+3
| | | | | | | | | | | Now by default all @options commands get passed a list of argument strings instead of a single argument string. This is a much easier and more robust behavior to deal with. Additionally, command-line arguments are intelligently separated based on location of quotes to group things into a single argument. WARNING: This change breaks backward compatibility for older applicaitons based on cmd2. To change the behavior to the way it used to be, add the following code to the __init__() method of our class derived from cmd2.Cmd: cmd2.set_use_arg_list(False) This change really does make it easier for developers new to using cmd2 however. It is to the point where I create all custom commands with @options, even if I use an empty list for the options because the argument parsing is just much better this way.
* Updated documentation and examplesTodd Leonhardt2017-06-141-2/+2
| | | | | | | | | Added information related to the new pyscript command. The old way of running Python scripts via "py run()" should be considered deprecated. The new "pyscript" command is superior in two significant ways: 1) It supports tab-completion of file system paths 2) It allows the user to pass command-line arguments to scripts
* Updated an example, features, and changes based on new support for path and ↵Todd Leonhardt2017-05-171-12/+3
| | | | command completion
* Improved the CmdResult namedtuple subclassTodd Leonhardt2017-03-141-5/+5
| | | | | | The last two arguments (err and war) are now optional. Only the 1st argument (out) is required. err and war default to empty strings.
* Added intro with unicode characters to one example.Todd Leonhardt2017-03-141-3/+5
|
* Improved examplesTodd Leonhardt2017-03-111-3/+23
| | | | | | Added the pirate8.py example from Catherine's PyCon2010 talk as pirate.py with some cleanups done. Added an example of a complete_* method for command argument completion to the python_scripting.py example.
* Added an example for how conditional control flow of a cmd2 application can ↵Todd Leonhardt2017-03-111-0/+102
be achieved via the py command and python scripts.