Integrates the argparse and cmd modules.
Project description
argshell
Integrates the argparse and cmd modules to create custom shells with argparse functionality.
Installation
Install with:
pip install argshell
Usage
Custom shells are created by subclassing the ArgShell class and adding functions of the form do_*()
, just like the cmd.Cmd class.
The ArgShell
class contains a rich.console.Console
object that can be used to print renderables.
In terminal:
Rather than being limited to input strings, you can use argparse
style parsers for shell commands.
Create a function that instantiates an ArgShellParser
instance, adds arguments, and then returns the ArgShellParser
object.
Then you can can decorate do_*
functions using with_parser()
to pass a Namespace
object instead of a string.
In terminal:
The with_parser
function also accepts an optional list of functions that accept and return an argshell.Namespace
object.
These functions will be executed in order after the parser function parses the arguments.
In terminal:
When using your shell, entering help command
will, in addition to the command's doc string,
print the help message of the parser that decorates it, if it is decorated.
The capture
command can be used to save an svg of another command's output by prepending to a command.
(NOTE: This only works for output printed with ArgShell
's console
member mentioned earlier.)
The font size is proportional to your terminal width when using the command and any text your terminal wraps will be truncated in the svg.
The following would create a file called add.svg
in your current directory:
The saved svg:
There's also a "hidden" command for generating documentation called shell_docs
.
Executing that command for MyShell
:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file argshell-1.6.4.tar.gz
.
File metadata
- Download URL: argshell-1.6.4.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26b9e0f45e235674235a70a792be27c75015905c4907fbd02bc461fc3f381323 |
|
MD5 | 79c92d9a01368e3ddd7451766066238c |
|
BLAKE2b-256 | c6ae1c02f49279e1d809a60bc6c391ef900dad25b6e63414f3da3fff543e27be |
File details
Details for the file argshell-1.6.4-py3-none-any.whl
.
File metadata
- Download URL: argshell-1.6.4-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c0f1cc6eb27e7ebc16a9ad90952e538887e64dac37ca91b11cd932755ee4c53 |
|
MD5 | 040fd92485f9d1560535318b0c84bead |
|
BLAKE2b-256 | 987dcff52eb36b8d1dde60d96d68fc7f1015fa4a79588fa09b96fa54c7909a5d |