Name | argshell JSON |
Version |
1.6.5
JSON |
| download |
home_page | None |
Summary | Integrates the argparse and cmd modules. |
upload_time | 2024-12-13 23:15:44 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.10 |
license | None |
keywords |
argparse
cmd
commandline
shell
terminal
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# argshell
Integrates the argparse and cmd modules to create custom shells with argparse functionality.
## Installation
Install with:
<pre>
pip install argshell
</pre>
## 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.
![](assets/myshell.svg)
In terminal:
![](assets/echo.svg)
---
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.
![](assets/myshell_with_parser.svg)
In terminal:
![](assets/add_help.svg)
![](assets/add.svg)
---
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.
![](assets/post_parser.svg)
In terminal:
![](assets/invert_add.svg)
![](assets/invert_double_add.svg)
---
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.
![](assets/help_list.svg)
![](assets/help.svg)
---
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:
![](assets/capture.svg)
The saved svg:
![](assets/add.svg)
---
There's also a "hidden" command for generating documentation called `shell_docs`.
![](assets/help_shell_docs.svg)
Executing that command for `MyShell`:
![](assets/shell_docs.svg)
Raw data
{
"_id": null,
"home_page": null,
"name": "argshell",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "argparse, cmd, commandline, shell, terminal",
"author": null,
"author_email": "Matt Manes <mattmanes@pm.me>",
"download_url": "https://files.pythonhosted.org/packages/3f/84/6c2884d34be14613097761c34ef3c929caabdbab50ff6dec6cab0dcac195/argshell-1.6.5.tar.gz",
"platform": null,
"description": "# argshell\n\nIntegrates the argparse and cmd modules to create custom shells with argparse functionality. \n\n## Installation\n\nInstall with:\n\n<pre>\npip install argshell\n</pre>\n\n\n\n## Usage\n\nCustom shells are created by subclassing the ArgShell class and adding functions of the form `do_*()`, just like the cmd.Cmd class. \nThe `ArgShell` class contains a `rich.console.Console` object that can be used to print renderables. \n![](assets/myshell.svg)\n\nIn terminal:\n![](assets/echo.svg)\n\n---\n\nRather than being limited to input strings, you can use `argparse` style parsers for shell commands. \nCreate a function that instantiates an `ArgShellParser` instance, adds arguments, and then returns the `ArgShellParser` object. \nThen you can can decorate `do_*` functions using `with_parser()` to pass a `Namespace` object instead of a string.\n![](assets/myshell_with_parser.svg)\n\nIn terminal:\n![](assets/add_help.svg)\n![](assets/add.svg)\n\n---\n\nThe `with_parser` function also accepts an optional list of functions that accept and return an `argshell.Namespace` object. \nThese functions will be executed in order after the parser function parses the arguments.\n![](assets/post_parser.svg)\n\nIn terminal:\n![](assets/invert_add.svg)\n![](assets/invert_double_add.svg)\n\n--- \n\nWhen using your shell, entering `help command` will, in addition to the command's doc string,\nprint the help message of the parser that decorates it, if it is decorated. \n![](assets/help_list.svg)\n![](assets/help.svg)\n\n---\n\nThe `capture` command can be used to save an svg of another command's output by prepending to a command. \n(NOTE: This only works for output printed with `ArgShell`'s `console` member mentioned earlier.) \nThe font size is proportional to your terminal width when using the command and any text your terminal wraps will be truncated in the svg. \nThe following would create a file called `add.svg` in your current directory:\n![](assets/capture.svg)\nThe saved svg:\n![](assets/add.svg)\n\n---\n\nThere's also a \"hidden\" command for generating documentation called `shell_docs`.\n![](assets/help_shell_docs.svg)\n\nExecuting that command for `MyShell`:\n![](assets/shell_docs.svg)",
"bugtrack_url": null,
"license": null,
"summary": "Integrates the argparse and cmd modules.",
"version": "1.6.5",
"project_urls": {
"Documentation": "https://github.com/matt-manes/argshell/tree/main/docs",
"Homepage": "https://github.com/matt-manes/argshell",
"Source code": "https://github.com/matt-manes/argshell/tree/main/src/argshell"
},
"split_keywords": [
"argparse",
" cmd",
" commandline",
" shell",
" terminal"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5a8171b575b2c937f4f96cbb0cb595359e5a4707a5d317408e1e17e74cd894d1",
"md5": "aac347925b4563dc743a034145d2fefa",
"sha256": "18fa58668fdd5f53f1b8ac22f7ae418b3d17a438c7a26a2f61408f8514d9ff2c"
},
"downloads": -1,
"filename": "argshell-1.6.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "aac347925b4563dc743a034145d2fefa",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 9456,
"upload_time": "2024-12-13T23:15:42",
"upload_time_iso_8601": "2024-12-13T23:15:42.223305Z",
"url": "https://files.pythonhosted.org/packages/5a/81/71b575b2c937f4f96cbb0cb595359e5a4707a5d317408e1e17e74cd894d1/argshell-1.6.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3f846c2884d34be14613097761c34ef3c929caabdbab50ff6dec6cab0dcac195",
"md5": "38e9f0a34ee9a0aed33e79e73c1e9656",
"sha256": "908c71e0ce4b599eb89610417036d4d5cc91e112354ce0c4b1c3d011318f73f0"
},
"downloads": -1,
"filename": "argshell-1.6.5.tar.gz",
"has_sig": false,
"md5_digest": "38e9f0a34ee9a0aed33e79e73c1e9656",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 8668,
"upload_time": "2024-12-13T23:15:44",
"upload_time_iso_8601": "2024-12-13T23:15:44.884036Z",
"url": "https://files.pythonhosted.org/packages/3f/84/6c2884d34be14613097761c34ef3c929caabdbab50ff6dec6cab0dcac195/argshell-1.6.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-13 23:15:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "matt-manes",
"github_project": "argshell",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "argshell"
}