Name | rlane-libcli JSON |
Version |
1.0.8
JSON |
| download |
home_page | None |
Summary | Command line interface framework |
upload_time | 2024-11-16 16:49:14 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.10 |
license | MIT |
keywords |
argparse
cli
color
markdown
python
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
## libcli
Command line interface framework.
The `libcli` package, built on
[argparse](https://docs.python.org/3/library/argparse.html), provides
functions and features that are common to or desired by many command
line applications:
* Colorized help output, with `prog -h`, or `prog --help`.
* Help output in `Markdown` format, with `prog --md-help`.
* Print all help (top command, and all subcommands), with `prog -H`, or
`prog --long-help`. (For commands with subcommands).
* Configure logging, with `-v`, or `--verbose`
(`"-v"`=INFO, `"-vv"`=DEBUG, `"-vvv"`=TRACE). Integrated
with [loguru](https://github.com/Delgan/loguru) and
[logging](https://docs.python.org/3/library/logging.html).
* Print the current version of the application, with `-V`, or `--version`;
uses value from application's package metadata.
* Load configuration from a file, *before* parsing the command line,
with `--config FILE`. (Well, it parsed at least that much.. and "-v"
for debugging "--config" itself.) This allows values from the config
file to be available when building the `argparse.ArgumentParser`, for
setting defaults, or including within help strings of arguments/options.
* Print the active configuration, after loading the config file, with `--print-config`.
* Print the application's URL, with `--print-url`;
uses value from application's package metadata.
* Integrate with [argcomplete](https://github.com/kislyuk/argcomplete),
with `--completion`.
* Automatic inclusion of all common options, above.
* Normalized help text of all command line arguments/options.
* Force the first letter of all help strings to be upper case.
* Force all help strings to end with a period.
* Provides a function `add_default_to_help` to consistently include
a default value in an argument/option's help string.
* Supports single command applications, and command/sub-commands applications.
### class BaseCLI
Command line interface base class.
$ cat minimal.py
from libcli import BaseCLI
class HelloCLI(BaseCLI):
def main(self) -> None:
print("Hello")
if __name__ == "__main__":
HelloCLI().main()
$ python minimal.py -h
Usage: minimal.py [-h] [-v] [-V] [--print-config] [--print-url] [--completion [SHELL]]
General Options:
-h, --help Show this help message and exit.
-v, --verbose `-v` for detailed output and `-vv` for more detailed.
-V, --version Print version number and exit.
--print-config Print effective config and exit.
--print-url Print project url and exit.
--completion [SHELL] Print completion scripts for `SHELL` and exit (default: `bash`).
$ cat simple.py
from libcli import BaseCLI
class HelloCLI(BaseCLI):
def init_parser(self) -> None:
self.parser = self.ArgumentParser(
prog=__package__,
description="This program says hello.",
)
def add_arguments(self) -> None:
self.parser.add_argument(
"--spanish",
action="store_true",
help="Say hello in Spanish.",
)
self.parser.add_argument(
"name",
help="The person to say hello to.",
)
def main(self) -> None:
if self.options.spanish:
print(f"Hola, {self.options.name}!")
else:
print(f"Hello, {self.options.name}!")
if __name__ == "__main__":
HelloCLI().main()
$ python simply.py -h
Usage: simple.py [--spanish] [-h] [-v] [-V] [--print-config] [--print-url]
[--completion [SHELL]] name
This program says hello.
Positional Arguments:
name The person to say hello to.
Options:
--spanish Say hello in Spanish.
General Options:
-h, --help Show this help message and exit.
-v, --verbose `-v` for detailed output and `-vv` for more detailed.
-V, --version Print version number and exit.
--print-config Print effective config and exit.
--print-url Print project url and exit.
--completion [SHELL] Print completion scripts for `SHELL` and exit (default: `bash`).
### class BaseCmd
Base command class; for commands with subcommands.
$ cat complex.py
from libcli import BaseCLI, BaseCmd
class EnglishCmd(BaseCmd):
def init_command(self) -> None:
parser = self.add_subcommand_parser(
"english",
help="Say hello in English",
description="The `%(prog)s` command says hello in English.",
)
parser.add_argument(
"name",
help="The person to say hello to.",
)
def run(self) -> None:
print(f"Hello {self.options.name}!")
class SpanishCmd(BaseCmd):
def init_command(self) -> None:
parser = self.add_subcommand_parser(
"spanish",
help="Say hello in Spanish",
description="The `%(prog)s` command says hello in Spanish.",
)
parser.add_argument(
"name",
help="The person to say hello to.",
)
def run(self) -> None:
print(f"Hola {self.options.name}!")
class HelloCLI(BaseCLI):
def init_parser(self) -> None:
self.parser = self.ArgumentParser(
prog=__package__,
description="This program says hello.",
)
def add_arguments(self) -> None:
self.add_subcommand_classes([EnglishCmd, SpanishCmd])
def main(self) -> None:
if not self.options.cmd:
self.parser.print_help()
self.parser.exit(2, "error: Missing COMMAND")
self.options.cmd()
if __name__ == "__main__":
HelloCLI().main()
$ python complex.py -H
---------------------------------- COMPLEX.PY ----------------------------------
usage: complex.py [-h] [-H] [-v] [-V] [--print-config] [--print-url]
[--completion [SHELL]]
COMMAND ...
This program says hello.
Specify one of:
COMMAND
english Say hello in English.
spanish Say hello in Spanish.
General options:
-h, --help Show this help message and exit.
-H, --long-help Show help for all commands and exit.
-v, --verbose `-v` for detailed output and `-vv` for more detailed.
-V, --version Print version number and exit.
--print-config Print effective config and exit.
--print-url Print project url and exit.
--completion [SHELL] Print completion scripts for `SHELL` and exit
(default: `bash`).
------------------------------ COMPLEX.PY ENGLISH ------------------------------
usage: complex.py english [-h] name
The `complex.py english` command says hello in English.
positional arguments:
name The person to say hello to.
options:
-h, --help Show this help message and exit.
------------------------------ COMPLEX.PY SPANISH ------------------------------
usage: complex.py spanish [-h] name
The `complex.py spanish` command says hello in Spanish.
positional arguments:
name The person to say hello to.
options:
-h, --help Show this help message and exit.
Raw data
{
"_id": null,
"home_page": null,
"name": "rlane-libcli",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "argparse, cli, color, markdown, python",
"author": null,
"author_email": "Russel Lane <russel@rlane.com>",
"download_url": "https://files.pythonhosted.org/packages/c5/7c/b4b5e40616496c9aa1945fe5b5ab30c486afb310fcd4a84d495593faf24b/rlane_libcli-1.0.8.tar.gz",
"platform": null,
"description": "## libcli\n\nCommand line interface framework.\n\nThe `libcli` package, built on\n[argparse](https://docs.python.org/3/library/argparse.html), provides\nfunctions and features that are common to or desired by many command\nline applications:\n\n* Colorized help output, with `prog -h`, or `prog --help`.\n\n* Help output in `Markdown` format, with `prog --md-help`.\n\n* Print all help (top command, and all subcommands), with `prog -H`, or\n`prog --long-help`. (For commands with subcommands).\n\n* Configure logging, with `-v`, or `--verbose`\n(`\"-v\"`=INFO, `\"-vv\"`=DEBUG, `\"-vvv\"`=TRACE). Integrated\nwith [loguru](https://github.com/Delgan/loguru) and\n[logging](https://docs.python.org/3/library/logging.html).\n\n* Print the current version of the application, with `-V`, or `--version`;\nuses value from application's package metadata.\n\n* Load configuration from a file, *before* parsing the command line,\nwith `--config FILE`. (Well, it parsed at least that much.. and \"-v\"\nfor debugging \"--config\" itself.) This allows values from the config\nfile to be available when building the `argparse.ArgumentParser`, for\nsetting defaults, or including within help strings of arguments/options.\n\n* Print the active configuration, after loading the config file, with `--print-config`.\n\n* Print the application's URL, with `--print-url`;\nuses value from application's package metadata.\n\n* Integrate with [argcomplete](https://github.com/kislyuk/argcomplete),\nwith `--completion`.\n\n* Automatic inclusion of all common options, above.\n\n* Normalized help text of all command line arguments/options.\n\n * Force the first letter of all help strings to be upper case.\n * Force all help strings to end with a period.\n\n* Provides a function `add_default_to_help` to consistently include\na default value in an argument/option's help string.\n\n* Supports single command applications, and command/sub-commands applications.\n\n\n### class BaseCLI\n\nCommand line interface base class.\n\n$ cat minimal.py\n\n from libcli import BaseCLI\n class HelloCLI(BaseCLI):\n def main(self) -> None:\n print(\"Hello\")\n if __name__ == \"__main__\":\n HelloCLI().main()\n\n$ python minimal.py -h\n\n Usage: minimal.py [-h] [-v] [-V] [--print-config] [--print-url] [--completion [SHELL]]\n\n General Options:\n -h, --help Show this help message and exit.\n -v, --verbose `-v` for detailed output and `-vv` for more detailed.\n -V, --version Print version number and exit.\n --print-config Print effective config and exit.\n --print-url Print project url and exit.\n --completion [SHELL] Print completion scripts for `SHELL` and exit (default: `bash`).\n\n$ cat simple.py\n\n from libcli import BaseCLI\n\n class HelloCLI(BaseCLI):\n\n def init_parser(self) -> None:\n self.parser = self.ArgumentParser(\n prog=__package__,\n description=\"This program says hello.\",\n )\n\n def add_arguments(self) -> None:\n self.parser.add_argument(\n \"--spanish\",\n action=\"store_true\",\n help=\"Say hello in Spanish.\",\n )\n self.parser.add_argument(\n \"name\",\n help=\"The person to say hello to.\",\n )\n\n def main(self) -> None:\n if self.options.spanish:\n print(f\"Hola, {self.options.name}!\")\n else:\n print(f\"Hello, {self.options.name}!\")\n\n if __name__ == \"__main__\":\n HelloCLI().main()\n\n$ python simply.py -h\n\n Usage: simple.py [--spanish] [-h] [-v] [-V] [--print-config] [--print-url]\n [--completion [SHELL]] name\n\n This program says hello.\n\n Positional Arguments:\n name The person to say hello to.\n\n Options:\n --spanish Say hello in Spanish.\n\n General Options:\n -h, --help Show this help message and exit.\n -v, --verbose `-v` for detailed output and `-vv` for more detailed.\n -V, --version Print version number and exit.\n --print-config Print effective config and exit.\n --print-url Print project url and exit.\n --completion [SHELL] Print completion scripts for `SHELL` and exit (default: `bash`).\n\n\n\n### class BaseCmd\n\nBase command class; for commands with subcommands.\n\n$ cat complex.py\n\n from libcli import BaseCLI, BaseCmd\n\n class EnglishCmd(BaseCmd):\n\n def init_command(self) -> None:\n\n parser = self.add_subcommand_parser(\n \"english\",\n help=\"Say hello in English\",\n description=\"The `%(prog)s` command says hello in English.\",\n )\n\n parser.add_argument(\n \"name\",\n help=\"The person to say hello to.\",\n )\n\n def run(self) -> None:\n print(f\"Hello {self.options.name}!\")\n\n class SpanishCmd(BaseCmd):\n\n def init_command(self) -> None:\n\n parser = self.add_subcommand_parser(\n \"spanish\",\n help=\"Say hello in Spanish\",\n description=\"The `%(prog)s` command says hello in Spanish.\",\n )\n\n parser.add_argument(\n \"name\",\n help=\"The person to say hello to.\",\n )\n\n def run(self) -> None:\n print(f\"Hola {self.options.name}!\")\n\n class HelloCLI(BaseCLI):\n\n def init_parser(self) -> None:\n self.parser = self.ArgumentParser(\n prog=__package__,\n description=\"This program says hello.\",\n )\n\n def add_arguments(self) -> None:\n self.add_subcommand_classes([EnglishCmd, SpanishCmd])\n\n def main(self) -> None:\n if not self.options.cmd:\n self.parser.print_help()\n self.parser.exit(2, \"error: Missing COMMAND\")\n self.options.cmd()\n\n if __name__ == \"__main__\":\n HelloCLI().main()\n\n$ python complex.py -H\n\n ---------------------------------- COMPLEX.PY ----------------------------------\n\n usage: complex.py [-h] [-H] [-v] [-V] [--print-config] [--print-url]\n [--completion [SHELL]]\n COMMAND ...\n\n This program says hello.\n\n Specify one of:\n COMMAND\n english Say hello in English.\n spanish Say hello in Spanish.\n\n General options:\n -h, --help Show this help message and exit.\n -H, --long-help Show help for all commands and exit.\n -v, --verbose `-v` for detailed output and `-vv` for more detailed.\n -V, --version Print version number and exit.\n --print-config Print effective config and exit.\n --print-url Print project url and exit.\n --completion [SHELL] Print completion scripts for `SHELL` and exit\n (default: `bash`).\n\n ------------------------------ COMPLEX.PY ENGLISH ------------------------------\n\n usage: complex.py english [-h] name\n\n The `complex.py english` command says hello in English.\n\n positional arguments:\n name The person to say hello to.\n\n options:\n -h, --help Show this help message and exit.\n\n ------------------------------ COMPLEX.PY SPANISH ------------------------------\n\n usage: complex.py spanish [-h] name\n\n The `complex.py spanish` command says hello in Spanish.\n\n positional arguments:\n name The person to say hello to.\n\n options:\n -h, --help Show this help message and exit.\n\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Command line interface framework",
"version": "1.0.8",
"project_urls": {
"Homepage": "https://github.com/russellane/libcli"
},
"split_keywords": [
"argparse",
" cli",
" color",
" markdown",
" python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7fd26db38c96a62ecd2e367ec5373a9ec60bc115165bbcc249ad9b79d8de2b08",
"md5": "56e4d5684c46e98addbda0bf63daa165",
"sha256": "451092677facd4e8e5c3df6f9f21969fc69b85b1278d1f9e99166fd49a1936d1"
},
"downloads": -1,
"filename": "rlane_libcli-1.0.8-py3-none-any.whl",
"has_sig": false,
"md5_digest": "56e4d5684c46e98addbda0bf63daa165",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 20579,
"upload_time": "2024-11-16T16:49:13",
"upload_time_iso_8601": "2024-11-16T16:49:13.874387Z",
"url": "https://files.pythonhosted.org/packages/7f/d2/6db38c96a62ecd2e367ec5373a9ec60bc115165bbcc249ad9b79d8de2b08/rlane_libcli-1.0.8-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c57cb4b5e40616496c9aa1945fe5b5ab30c486afb310fcd4a84d495593faf24b",
"md5": "f65984c250b106c5616862c1fcb9d880",
"sha256": "16fb629a7498ede181e6439f5933a865e0a68d93273d6fcfdd27cac11732be92"
},
"downloads": -1,
"filename": "rlane_libcli-1.0.8.tar.gz",
"has_sig": false,
"md5_digest": "f65984c250b106c5616862c1fcb9d880",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 18584,
"upload_time": "2024-11-16T16:49:14",
"upload_time_iso_8601": "2024-11-16T16:49:14.939685Z",
"url": "https://files.pythonhosted.org/packages/c5/7c/b4b5e40616496c9aa1945fe5b5ab30c486afb310fcd4a84d495593faf24b/rlane_libcli-1.0.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-16 16:49:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "russellane",
"github_project": "libcli",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "rlane-libcli"
}