argshell


Nameargshell JSON
Version 1.6.4 PyPI version JSON
download
home_pageNone
SummaryIntegrates the argparse and cmd modules.
upload_time2024-06-07 04:37:15
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
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/c6/ae/1c02f49279e1d809a60bc6c391ef900dad25b6e63414f3da3fff543e27be/argshell-1.6.4.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.4",
    "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": "987dcff52eb36b8d1dde60d96d68fc7f1015fa4a79588fa09b96fa54c7909a5d",
                "md5": "040fd92485f9d1560535318b0c84bead",
                "sha256": "3c0f1cc6eb27e7ebc16a9ad90952e538887e64dac37ca91b11cd932755ee4c53"
            },
            "downloads": -1,
            "filename": "argshell-1.6.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "040fd92485f9d1560535318b0c84bead",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 9472,
            "upload_time": "2024-06-07T04:37:14",
            "upload_time_iso_8601": "2024-06-07T04:37:14.366749Z",
            "url": "https://files.pythonhosted.org/packages/98/7d/cff52eb36b8d1dde60d96d68fc7f1015fa4a79588fa09b96fa54c7909a5d/argshell-1.6.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c6ae1c02f49279e1d809a60bc6c391ef900dad25b6e63414f3da3fff543e27be",
                "md5": "79c92d9a01368e3ddd7451766066238c",
                "sha256": "26b9e0f45e235674235a70a792be27c75015905c4907fbd02bc461fc3f381323"
            },
            "downloads": -1,
            "filename": "argshell-1.6.4.tar.gz",
            "has_sig": false,
            "md5_digest": "79c92d9a01368e3ddd7451766066238c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 8677,
            "upload_time": "2024-06-07T04:37:15",
            "upload_time_iso_8601": "2024-06-07T04:37:15.655150Z",
            "url": "https://files.pythonhosted.org/packages/c6/ae/1c02f49279e1d809a60bc6c391ef900dad25b6e63414f3da3fff543e27be/argshell-1.6.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-07 04:37:15",
    "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"
}
        
Elapsed time: 0.67810s