xpresscli


Namexpresscli JSON
Version 0.1.0 PyPI version JSON
download
home_page
SummaryLibrary to simplify the process of creating powerful CLI parsers
upload_time2023-09-16 10:05:18
maintainer
docs_urlNone
authorPaul K Korir
requires_python>=3.6
licenseApache Software License 2.0
keywords cli parser command line interface argument option subcommand subparser argparse argh click docopt getopt getopts optparse optik optparse python python3 argparse argparse-subcommand argparse-subparsers argparse-subparser argparse-subcommand-parser argparse-subcommands argparse
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## Example Usage

Assumptions:

- The file ``cli.toml`` exists in the current working directory; otherwise the user must specify the path to the
  configuration file and pass it to the `Client` constructor.
- The file ``cli.toml`` contains the complete CLI description consisting of:
  - general description of the CLI handler;
  - detailed description of each client command;
  - details about how each command is routed;

First, we will work out the JSON schema for the client definition.

```json
{
  "client": {
    "prog": "sff",
    "description": "The EMDB-SFF Read/Write Toolkit (sfftk-rw)",
    "options": [
      {
        "name": [
          "-V",
          "--version"
        ],
        "help": "Show the version and exit",
        "action": "store_true"
      },
      {
        "name": [
          "-c",
          "--config-file"
        ],
        "help": "The path to the configuration file",
        "type": "str",
        "required": false
      },
      {
        "name": [
          "-v",
          "--verbose"
        ],
        "help": "Show more information about the analysis",
        "action": "store_true"
      }
    ]
  },
  "config_file": {
    "format": "ini",
    "filename": "sfftk.conf",
    "location": "user",
    "create": true
  },
  "commands": [
    {
      "name": "convert",
      "description": "Perform EMDB-SFF file format interconversions",
      "manager": "sfftkrw.sffrw.handle_convert",
      "groups": {
        "output": {
          "required": true,
          "mutually_exclusive": true
        }
      },
      "options": [
        {
          "name": [
            "from_file"
          ],
          "nargs": "*",
          "help": "file to convert from",
          "validator": "sfftkrw.validators.FileExists"
        },
        {
          "name": [
            "-D",
            "--details"
          ],
          "help": "populate the <details>...</details> in the XML file"
        },
        {
          "name": [
            "-R",
            "--primary-descriptor"
          ],
          "help": "populate the <primary_descriptor>...</primary_descriptor> in the XML file",
          "validator": "sfftkrw.validators.PrimaryDescriptor"
        },
        {
          "name": [
            "-x",
            "--exclude-geometry"
          ],
          "help": "exclude geometry data from the SFF file",
          "action": "store_true"
        },
        {
          "name": [
            "--json-indent"
          ],
          "help": "indentation level for JSON output",
          "type": "int",
          "default": 4
        },
        {
          "name": [
            "--json-sort-keys"
          ],
          "help": "sort keys for JSON output",
          "action": "store_true"
        },
        {
          "name": [
            "-o', '--output"
          ],
          "help": "output file name",
          "group": "output"
        },
        {
          "name": [
            "-f",
            "--format"
          ],
          "help": "output file format",
          "choices": [
            "sff",
            "xml",
            "json"
          ],
          "group": "output"
        }
      ]
    },
    {
      "name": "view",
      "description": "View EMDB-SFF files",
      "manager": "sfftkrw.sffrw.handle_view",
      "options": [
        {
          "name": [
            "from_file"
          ],
          "nargs": "*",
          "help": "file to view",
          "validator": "sfftkrw.validators.FileExists"
        },
        {
          "name": [
            "--sff-version"
          ],
          "help": "display the SFF version",
          "action": "store_true"
        }
      ]
    }
  ]
}
```
TOML is a much better way to capture the client description because it can accommodate coments and is far more compact (no extraneous braces). The equivalent TOML file is:
```toml
[client]
prog = "sff"
description = "The EMDB-SFF Read/Write Toolkit (sfftk-rw)"

[[client.options]]
name = ["-V", "--version"]
help = "Show the version and exit"
action = "store_true"

[[client.options]]
name = ["-c", "--config-file"]
help = "The path to the configuration file"
type = "str"
required = false

[[client.options]]
name = ["-v", "--verbose"]
help = "Show more information about the analysis"
action = "store_true"

[config_file]
format = "ini"
filename = "sfftk.conf"
location = "user"
create = true

[[commands]]
name = "convert"
description = "Perform EMDB-SFF file format interconversions"
manager = "sfftkrw.sffrw.handle_convert"

[commands.groups.output]
required = true
mutually_exclusive = true

[[commands.options]]
name = ["from_file"]
nargs = "*"
help = "file to convert from"
validator = "sfftkrw.validators.FileExists"

[[commands.options]]
name = ["-D", "--details"]
help = "populate the <details>...</details> in the XML file"

[[commands.options]]

name = ["-R", "--primary-descriptor"]
help = "populate the <primary_descriptor>...</primary_descriptor> in the XML file"
validator = "sfftkrw.validators.PrimaryDescriptor"

[[commands.options]]
name = ["-x", "--exclude-geometry"]
help = "exclude geometry data from the SFF file"
action = "store_true"

[[commands.options]]
name = ["--json-indent"]
help = "indentation level for JSON output"
type = "int"
default = 4

[[commands.options]]
name = ["--json-sort-keys"]
help = "sort keys for JSON output"
action = "store_true"

[[commands.options]]
name = ["-o", "--output"]
help = "output file name"
group = "output"

[[commands.options]]
name = ["-f", "--format"]
help = "output file format"
choices = ["sff", "xml", "json"]
group = "output"

[[commands]]
name = "view"
description = "View EMDB-SFF files"
manager = "sfftkrw.sffrw.handle_view"

[[commands.options]]
name = ["from_file"]
nargs = "*"
help = "file to view"
validator = "sfftkrw.validators.FileExists"

[[commands.options]]
name = ["--sff-version"]
help = "display the SFF version"
action = "store_true"
```

```python
import sys

from client import Client


def main():
    """Entry point for the application script"""
    with Client() as cli:
        exit_status = cli.execute()
    return exit_status


if __name__ == "__main__":
    sys.exit(main())
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "xpresscli",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "cli,parser,command,line,interface,argument,option,subcommand,subparser,argparse,argh,click,docopt,getopt,getopts,optparse,optik,optparse,python,python3,argparse,argparse-subcommand,argparse-subparsers,argparse-subparser,argparse-subcommand-parser,argparse-subcommands,argparse",
    "author": "Paul K Korir",
    "author_email": "paul.korir@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/a5/4d/26cf1056b07ec3304126cfeffe3915ca1f3b2dd26ec9ead62c8e4c41c34d/xpresscli-0.1.0.tar.gz",
    "platform": null,
    "description": "## Example Usage\n\nAssumptions:\n\n- The file ``cli.toml`` exists in the current working directory; otherwise the user must specify the path to the\n  configuration file and pass it to the `Client` constructor.\n- The file ``cli.toml`` contains the complete CLI description consisting of:\n  - general description of the CLI handler;\n  - detailed description of each client command;\n  - details about how each command is routed;\n\nFirst, we will work out the JSON schema for the client definition.\n\n```json\n{\n  \"client\": {\n    \"prog\": \"sff\",\n    \"description\": \"The EMDB-SFF Read/Write Toolkit (sfftk-rw)\",\n    \"options\": [\n      {\n        \"name\": [\n          \"-V\",\n          \"--version\"\n        ],\n        \"help\": \"Show the version and exit\",\n        \"action\": \"store_true\"\n      },\n      {\n        \"name\": [\n          \"-c\",\n          \"--config-file\"\n        ],\n        \"help\": \"The path to the configuration file\",\n        \"type\": \"str\",\n        \"required\": false\n      },\n      {\n        \"name\": [\n          \"-v\",\n          \"--verbose\"\n        ],\n        \"help\": \"Show more information about the analysis\",\n        \"action\": \"store_true\"\n      }\n    ]\n  },\n  \"config_file\": {\n    \"format\": \"ini\",\n    \"filename\": \"sfftk.conf\",\n    \"location\": \"user\",\n    \"create\": true\n  },\n  \"commands\": [\n    {\n      \"name\": \"convert\",\n      \"description\": \"Perform EMDB-SFF file format interconversions\",\n      \"manager\": \"sfftkrw.sffrw.handle_convert\",\n      \"groups\": {\n        \"output\": {\n          \"required\": true,\n          \"mutually_exclusive\": true\n        }\n      },\n      \"options\": [\n        {\n          \"name\": [\n            \"from_file\"\n          ],\n          \"nargs\": \"*\",\n          \"help\": \"file to convert from\",\n          \"validator\": \"sfftkrw.validators.FileExists\"\n        },\n        {\n          \"name\": [\n            \"-D\",\n            \"--details\"\n          ],\n          \"help\": \"populate the <details>...</details> in the XML file\"\n        },\n        {\n          \"name\": [\n            \"-R\",\n            \"--primary-descriptor\"\n          ],\n          \"help\": \"populate the <primary_descriptor>...</primary_descriptor> in the XML file\",\n          \"validator\": \"sfftkrw.validators.PrimaryDescriptor\"\n        },\n        {\n          \"name\": [\n            \"-x\",\n            \"--exclude-geometry\"\n          ],\n          \"help\": \"exclude geometry data from the SFF file\",\n          \"action\": \"store_true\"\n        },\n        {\n          \"name\": [\n            \"--json-indent\"\n          ],\n          \"help\": \"indentation level for JSON output\",\n          \"type\": \"int\",\n          \"default\": 4\n        },\n        {\n          \"name\": [\n            \"--json-sort-keys\"\n          ],\n          \"help\": \"sort keys for JSON output\",\n          \"action\": \"store_true\"\n        },\n        {\n          \"name\": [\n            \"-o', '--output\"\n          ],\n          \"help\": \"output file name\",\n          \"group\": \"output\"\n        },\n        {\n          \"name\": [\n            \"-f\",\n            \"--format\"\n          ],\n          \"help\": \"output file format\",\n          \"choices\": [\n            \"sff\",\n            \"xml\",\n            \"json\"\n          ],\n          \"group\": \"output\"\n        }\n      ]\n    },\n    {\n      \"name\": \"view\",\n      \"description\": \"View EMDB-SFF files\",\n      \"manager\": \"sfftkrw.sffrw.handle_view\",\n      \"options\": [\n        {\n          \"name\": [\n            \"from_file\"\n          ],\n          \"nargs\": \"*\",\n          \"help\": \"file to view\",\n          \"validator\": \"sfftkrw.validators.FileExists\"\n        },\n        {\n          \"name\": [\n            \"--sff-version\"\n          ],\n          \"help\": \"display the SFF version\",\n          \"action\": \"store_true\"\n        }\n      ]\n    }\n  ]\n}\n```\nTOML is a much better way to capture the client description because it can accommodate coments and is far more compact (no extraneous braces). The equivalent TOML file is:\n```toml\n[client]\nprog = \"sff\"\ndescription = \"The EMDB-SFF Read/Write Toolkit (sfftk-rw)\"\n\n[[client.options]]\nname = [\"-V\", \"--version\"]\nhelp = \"Show the version and exit\"\naction = \"store_true\"\n\n[[client.options]]\nname = [\"-c\", \"--config-file\"]\nhelp = \"The path to the configuration file\"\ntype = \"str\"\nrequired = false\n\n[[client.options]]\nname = [\"-v\", \"--verbose\"]\nhelp = \"Show more information about the analysis\"\naction = \"store_true\"\n\n[config_file]\nformat = \"ini\"\nfilename = \"sfftk.conf\"\nlocation = \"user\"\ncreate = true\n\n[[commands]]\nname = \"convert\"\ndescription = \"Perform EMDB-SFF file format interconversions\"\nmanager = \"sfftkrw.sffrw.handle_convert\"\n\n[commands.groups.output]\nrequired = true\nmutually_exclusive = true\n\n[[commands.options]]\nname = [\"from_file\"]\nnargs = \"*\"\nhelp = \"file to convert from\"\nvalidator = \"sfftkrw.validators.FileExists\"\n\n[[commands.options]]\nname = [\"-D\", \"--details\"]\nhelp = \"populate the <details>...</details> in the XML file\"\n\n[[commands.options]]\n\nname = [\"-R\", \"--primary-descriptor\"]\nhelp = \"populate the <primary_descriptor>...</primary_descriptor> in the XML file\"\nvalidator = \"sfftkrw.validators.PrimaryDescriptor\"\n\n[[commands.options]]\nname = [\"-x\", \"--exclude-geometry\"]\nhelp = \"exclude geometry data from the SFF file\"\naction = \"store_true\"\n\n[[commands.options]]\nname = [\"--json-indent\"]\nhelp = \"indentation level for JSON output\"\ntype = \"int\"\ndefault = 4\n\n[[commands.options]]\nname = [\"--json-sort-keys\"]\nhelp = \"sort keys for JSON output\"\naction = \"store_true\"\n\n[[commands.options]]\nname = [\"-o\", \"--output\"]\nhelp = \"output file name\"\ngroup = \"output\"\n\n[[commands.options]]\nname = [\"-f\", \"--format\"]\nhelp = \"output file format\"\nchoices = [\"sff\", \"xml\", \"json\"]\ngroup = \"output\"\n\n[[commands]]\nname = \"view\"\ndescription = \"View EMDB-SFF files\"\nmanager = \"sfftkrw.sffrw.handle_view\"\n\n[[commands.options]]\nname = [\"from_file\"]\nnargs = \"*\"\nhelp = \"file to view\"\nvalidator = \"sfftkrw.validators.FileExists\"\n\n[[commands.options]]\nname = [\"--sff-version\"]\nhelp = \"display the SFF version\"\naction = \"store_true\"\n```\n\n```python\nimport sys\n\nfrom client import Client\n\n\ndef main():\n    \"\"\"Entry point for the application script\"\"\"\n    with Client() as cli:\n        exit_status = cli.execute()\n    return exit_status\n\n\nif __name__ == \"__main__\":\n    sys.exit(main())\n```\n",
    "bugtrack_url": null,
    "license": "Apache Software License 2.0",
    "summary": "Library to simplify the process of creating powerful CLI parsers",
    "version": "0.1.0",
    "project_urls": {
        "changelog": "https://github.com/paulkorir/xpresscli",
        "documentation": "https://github.com/paulkorir/xpresscli",
        "homepage": "https://github.com/paulkorir/xpresscli",
        "repository": "https://github.com/paulkorir/xpresscli"
    },
    "split_keywords": [
        "cli",
        "parser",
        "command",
        "line",
        "interface",
        "argument",
        "option",
        "subcommand",
        "subparser",
        "argparse",
        "argh",
        "click",
        "docopt",
        "getopt",
        "getopts",
        "optparse",
        "optik",
        "optparse",
        "python",
        "python3",
        "argparse",
        "argparse-subcommand",
        "argparse-subparsers",
        "argparse-subparser",
        "argparse-subcommand-parser",
        "argparse-subcommands",
        "argparse"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "892332f5ba26e3340964591a475c6ca70d8ee8093d60236918e208309fc4b46d",
                "md5": "fdcf9d665843f57bbbd6b424fcf06f48",
                "sha256": "72d0f26f70ae0b8e620414c35ca0024a1afd76d97818f60ec60f84db09ba6908"
            },
            "downloads": -1,
            "filename": "xpresscli-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fdcf9d665843f57bbbd6b424fcf06f48",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 4349,
            "upload_time": "2023-09-16T10:05:16",
            "upload_time_iso_8601": "2023-09-16T10:05:16.085057Z",
            "url": "https://files.pythonhosted.org/packages/89/23/32f5ba26e3340964591a475c6ca70d8ee8093d60236918e208309fc4b46d/xpresscli-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a54d26cf1056b07ec3304126cfeffe3915ca1f3b2dd26ec9ead62c8e4c41c34d",
                "md5": "40988a81fcbb997dd282fabf277018ef",
                "sha256": "7095ba4143b4f19b84e7d1412b3e7a09fc4afbb86deafa16c0ffe6a0aed19d77"
            },
            "downloads": -1,
            "filename": "xpresscli-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "40988a81fcbb997dd282fabf277018ef",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 4739,
            "upload_time": "2023-09-16T10:05:18",
            "upload_time_iso_8601": "2023-09-16T10:05:18.534144Z",
            "url": "https://files.pythonhosted.org/packages/a5/4d/26cf1056b07ec3304126cfeffe3915ca1f3b2dd26ec9ead62c8e4c41c34d/xpresscli-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-16 10:05:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "paulkorir",
    "github_project": "xpresscli",
    "github_not_found": true,
    "lcname": "xpresscli"
}
        
Elapsed time: 1.41420s