argshell


Nameargshell JSON
Version 1.6.3 PyPI version JSON
download
home_page
SummaryIntegrates the argparse and cmd modules.
upload_time2024-02-25 01:00:40
maintainer
docs_urlNone
author
requires_python>=3.10
license
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": "",
    "name": "argshell",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "argparse,cmd,commandline,shell,terminal",
    "author": "",
    "author_email": "Matt Manes <mattmanes@pm.me>",
    "download_url": "https://files.pythonhosted.org/packages/f9/e7/17ba4eee7a30b1ff11cd03e58a0910895cf554ac7a801cee682e5f7c7d96/argshell-1.6.3.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": "",
    "summary": "Integrates the argparse and cmd modules.",
    "version": "1.6.3",
    "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": "737cd9a02a9787c52dc3c983af7ab5ce39ae3a5b2f7b43c634826a26fcbb5935",
                "md5": "c7f13632953c0835d3f62723dcc9f079",
                "sha256": "80e9829d856aefd1216f688c0e0bc981506d57fb88f900606c453ef37ca05dc2"
            },
            "downloads": -1,
            "filename": "argshell-1.6.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c7f13632953c0835d3f62723dcc9f079",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 9468,
            "upload_time": "2024-02-25T01:00:39",
            "upload_time_iso_8601": "2024-02-25T01:00:39.206762Z",
            "url": "https://files.pythonhosted.org/packages/73/7c/d9a02a9787c52dc3c983af7ab5ce39ae3a5b2f7b43c634826a26fcbb5935/argshell-1.6.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f9e717ba4eee7a30b1ff11cd03e58a0910895cf554ac7a801cee682e5f7c7d96",
                "md5": "98ef7eaec9395aeccf3b105d672a4431",
                "sha256": "1375f22d8e4f6c99fe20f8c1f5f7d19be39663b75efe810130ac3456546e48bb"
            },
            "downloads": -1,
            "filename": "argshell-1.6.3.tar.gz",
            "has_sig": false,
            "md5_digest": "98ef7eaec9395aeccf3b105d672a4431",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 8672,
            "upload_time": "2024-02-25T01:00:40",
            "upload_time_iso_8601": "2024-02-25T01:00:40.574868Z",
            "url": "https://files.pythonhosted.org/packages/f9/e7/17ba4eee7a30b1ff11cd03e58a0910895cf554ac7a801cee682e5f7c7d96/argshell-1.6.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-25 01:00:40",
    "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.20789s