simpcli3


Namesimpcli3 JSON
Version 0.0.3 PyPI version JSON
download
home_pagehttps://github.com/haydenflinner/simpcli3
SummaryA Python3 library for turning functions into cmd-line programs trivially.
upload_time2021-04-21 23:49:54
maintainer
docs_urlNone
authorHayden Flinner
requires_python>=3.7
license
keywords cmd line command console argparse argparsing dataclass
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # simpcli3
A Python3 module for turning functions into cmd-line programs trivially.


## Examples
### Non-dataclass (simple function) example
```
from simpcli3 import CliApp
from typing import List

def myls(paths: List[str], exclude: List[str]=[], mystr: str=None, follow_symlinks: bool=False):
    print(f"Received args: {paths}\n")
    for path in paths:
        print(path)

if __name__ == "__main__":
    CliApp(myls).run()
```

### More advanced Example
This example actually uses a dataclass argument rather than a collection of arguments of primitive types.

```
from dataclasses import dataclass, field
from enum import Enum
from typing import List

class PrintFormat(Enum):
    LINE_PER_ENTRY = 1
    PRETTY = 2

@dataclass
class ListDirectoryArgs:
    paths: List[str] = field(metadata=dict(positional=True))
    exclude: List[str] = field(default_factory=list)
    print_format: PrintFormat = PrintFormat.PRETTY
    follow_symlinks: bool = True

def myls(lsargs: ListDirectoryArgs):
    print(f"Received args: {lsargs}\n")
    for path in lsargs.paths:
        print(path)

if __name__ == "__main__":
    from simpcli3 import CliApp
    CliApp(myls).run()
```

## Looking Forward

It would be nice to also be able to parse JSON / TOML config files into dataclasses, rather than having ever-growing cmd-line args.

### Prior Art
And why I didn't use it.

For argparse_dataclasses and argparse_dataclass reasons, see Improvements.

SimpleParsing (pip install simple_parsing). Different goals and approaches in terms of simplicity. For one, we
don't depend on numpy.


#### Improvements over projects based on
Modifications made from "argparse_dataclass":
  2. "positional" metadata arg as I think that's more intuitive than passing "args" directly.
  3. If type is enum, choices automatically specified, default given as string
     (kind of like "argparse_dataclasses" package, but with cleaner impl IMO)
  4. Better handling of bools (especially ones which default to True).
  5. Wrapper over field (idea lifted from argparse_dataclasses)


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/haydenflinner/simpcli3",
    "name": "simpcli3",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "cmd line command console argparse argparsing dataclass",
    "author": "Hayden Flinner",
    "author_email": "haydenflinner@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/cd/b8/56439a21c3d7ace70a1d8b0ea281a5cdf1983ad78ce7264d18245e68e53b/simpcli3-0.0.3.tar.gz",
    "platform": "",
    "description": "# simpcli3\nA Python3 module for turning functions into cmd-line programs trivially.\n\n\n## Examples\n### Non-dataclass (simple function) example\n```\nfrom simpcli3 import CliApp\nfrom typing import List\n\ndef myls(paths: List[str], exclude: List[str]=[], mystr: str=None, follow_symlinks: bool=False):\n    print(f\"Received args: {paths}\\n\")\n    for path in paths:\n        print(path)\n\nif __name__ == \"__main__\":\n    CliApp(myls).run()\n```\n\n### More advanced Example\nThis example actually uses a dataclass argument rather than a collection of arguments of primitive types.\n\n```\nfrom dataclasses import dataclass, field\nfrom enum import Enum\nfrom typing import List\n\nclass PrintFormat(Enum):\n    LINE_PER_ENTRY = 1\n    PRETTY = 2\n\n@dataclass\nclass ListDirectoryArgs:\n    paths: List[str] = field(metadata=dict(positional=True))\n    exclude: List[str] = field(default_factory=list)\n    print_format: PrintFormat = PrintFormat.PRETTY\n    follow_symlinks: bool = True\n\ndef myls(lsargs: ListDirectoryArgs):\n    print(f\"Received args: {lsargs}\\n\")\n    for path in lsargs.paths:\n        print(path)\n\nif __name__ == \"__main__\":\n    from simpcli3 import CliApp\n    CliApp(myls).run()\n```\n\n## Looking Forward\n\nIt would be nice to also be able to parse JSON / TOML config files into dataclasses, rather than having ever-growing cmd-line args.\n\n### Prior Art\nAnd why I didn't use it.\n\nFor argparse_dataclasses and argparse_dataclass reasons, see Improvements.\n\nSimpleParsing (pip install simple_parsing). Different goals and approaches in terms of simplicity. For one, we\ndon't depend on numpy.\n\n\n#### Improvements over projects based on\nModifications made from \"argparse_dataclass\":\n  2. \"positional\" metadata arg as I think that's more intuitive than passing \"args\" directly.\n  3. If type is enum, choices automatically specified, default given as string\n     (kind of like \"argparse_dataclasses\" package, but with cleaner impl IMO)\n  4. Better handling of bools (especially ones which default to True).\n  5. Wrapper over field (idea lifted from argparse_dataclasses)\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A Python3 library for turning functions into cmd-line programs trivially.",
    "version": "0.0.3",
    "split_keywords": [
        "cmd",
        "line",
        "command",
        "console",
        "argparse",
        "argparsing",
        "dataclass"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "0fd8c8985a6b2a2ffaed6de62325ad1d",
                "sha256": "d7677af7fa9ab55ef7353a850c1d184332310897225e7a1acd9c3212cdd41f32"
            },
            "downloads": -1,
            "filename": "simpcli3-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0fd8c8985a6b2a2ffaed6de62325ad1d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 13403,
            "upload_time": "2021-04-21T23:49:53",
            "upload_time_iso_8601": "2021-04-21T23:49:53.299307Z",
            "url": "https://files.pythonhosted.org/packages/1d/b1/f736204b2a3315e698ac35109ddcea89da96549c20d559ae915ecfa4e670/simpcli3-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "37db12b10b881d27b45f54b2fa484fdc",
                "sha256": "b011e5494327413f993bd07908d45f8cb498ea23fff3e7c13bdb94f20a4bc874"
            },
            "downloads": -1,
            "filename": "simpcli3-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "37db12b10b881d27b45f54b2fa484fdc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 13144,
            "upload_time": "2021-04-21T23:49:54",
            "upload_time_iso_8601": "2021-04-21T23:49:54.344853Z",
            "url": "https://files.pythonhosted.org/packages/cd/b8/56439a21c3d7ace70a1d8b0ea281a5cdf1983ad78ce7264d18245e68e53b/simpcli3-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-04-21 23:49:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "haydenflinner",
    "error": "Could not fetch GitHub repository",
    "lcname": "simpcli3"
}
        
Elapsed time: 0.27692s