{"id":17499443,"url":"https://github.com/russellane/libcli","last_synced_at":"2025-04-23T02:03:28.813Z","repository":{"id":65524804,"uuid":"496254544","full_name":"russellane/libcli","owner":"russellane","description":"Command line interface framework","archived":false,"fork":false,"pushed_at":"2024-11-17T14:10:54.000Z","size":203,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-23T02:03:04.357Z","etag":null,"topics":["cli","color","markdown","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/russellane.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-25T13:59:00.000Z","updated_at":"2024-11-16T17:10:43.000Z","dependencies_parsed_at":"2024-06-12T23:12:07.911Z","dependency_job_id":"b6e35924-eaf8-40f2-abf9-137c1fe2f99e","html_url":"https://github.com/russellane/libcli","commit_stats":{"total_commits":26,"total_committers":2,"mean_commits":13.0,"dds":0.07692307692307687,"last_synced_commit":"8d8b8ac9c2b47c07c64128c569ad3ddd6ea4a983"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/russellane%2Flibcli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/russellane%2Flibcli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/russellane%2Flibcli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/russellane%2Flibcli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/russellane","download_url":"https://codeload.github.com/russellane/libcli/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250354498,"owners_count":21416752,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","color","markdown","python"],"created_at":"2024-10-19T17:07:53.953Z","updated_at":"2025-04-23T02:03:28.794Z","avatar_url":"https://github.com/russellane.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## 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) -\u003e 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) -\u003e None:\n            self.parser = self.ArgumentParser(\n                prog=__package__,\n                description=\"This program says hello.\",\n            )\n\n        def add_arguments(self) -\u003e 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) -\u003e 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) -\u003e 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) -\u003e None:\n            print(f\"Hello {self.options.name}!\")\n\n    class SpanishCmd(BaseCmd):\n\n        def init_command(self) -\u003e 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) -\u003e None:\n            print(f\"Hola {self.options.name}!\")\n\n    class HelloCLI(BaseCLI):\n\n        def init_parser(self) -\u003e None:\n            self.parser = self.ArgumentParser(\n                prog=__package__,\n                description=\"This program says hello.\",\n            )\n\n        def add_arguments(self) -\u003e None:\n            self.add_subcommand_classes([EnglishCmd, SpanishCmd])\n\n        def main(self) -\u003e 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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frussellane%2Flibcli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frussellane%2Flibcli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frussellane%2Flibcli/lists"}