{"id":18005392,"url":"https://github.com/kootenpv/cliche","last_synced_at":"2025-04-13T02:20:11.377Z","repository":{"id":40476635,"uuid":"241486309","full_name":"kootenpv/cliche","owner":"kootenpv","description":"Build a simple command-line interface from your functions :computer:","archived":false,"fork":false,"pushed_at":"2024-10-11T23:54:11.000Z","size":265,"stargazers_count":107,"open_issues_count":8,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-04T04:35:37.039Z","etag":null,"topics":["cli","command-line","command-line-tool"],"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/kootenpv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2020-02-18T23:02:57.000Z","updated_at":"2024-12-30T22:24:50.000Z","dependencies_parsed_at":"2024-06-19T17:12:35.862Z","dependency_job_id":"024e8be3-11ae-4b62-a56e-dd2ac90ebf5a","html_url":"https://github.com/kootenpv/cliche","commit_stats":{"total_commits":110,"total_committers":5,"mean_commits":22.0,"dds":0.07272727272727275,"last_synced_commit":"f5c6f7447ed9dbda7ce18e3d15f0973df87bbd9f"},"previous_names":["kootenpv/mincli"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kootenpv%2Fcliche","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kootenpv%2Fcliche/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kootenpv%2Fcliche/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kootenpv%2Fcliche/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kootenpv","download_url":"https://codeload.github.com/kootenpv/cliche/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248654601,"owners_count":21140326,"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","command-line","command-line-tool"],"created_at":"2024-10-30T00:19:35.000Z","updated_at":"2025-04-13T02:20:11.359Z","avatar_url":"https://github.com/kootenpv.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./resources/logo.gif\"/\u003e\n\u003c/p\u003e\n\n# Cliche\n\nBuild a simple command-line interface from your functions.\n\nFeatures:\n\n- ✓ Least syntax required: you do not need to \"learn a library\" to use this\n- ✓ keeps it DRY (Don't Repeat yourself):\n  - it uses all information available like *annotations*, *default values* and *docstrings*... yet does not require them.\n- ✓ Just decorate a function with `@cli` - that is it - it can now be called as CLI but also remains usable by other functions (unlike the click library)\n- ✓ Works with booleans (flags) and lists (multiple args) automatically\n- ✓ Standing on the shoulders of giants (i.e. it uses argparse and learnings from others)\n- ✓ Prints returned python objects in JSON (unless passing `--raw`)\n- ✓ Colorized output automatically\n- ✓ Allows creating executable by using `cliche install \u003cmycli\u003e`\n- ✓ Creates shortcuts, e.g. a variable \"long_option\" will be usable like `--long-option` and `-l`\n- ✓ No external dependencies -\u003e lightweight\n\n## Examples\n\n#### Simplest Example\n\nYou want to make a calculator. You not only want its functions to be reusable, you also want it to be callable from command line.\n\n```python\n# calculator.py\nfrom cliche import cli\n\n@cli\ndef add(a: int, b: int):\n    return a + b\n```\n\nNow let's see how to use it from the command-line:\n\n```\npascal@archbook:~/calc$ cliche install calc\npascal@archbook:~/calc$ calc add --help\n\nusage: calc add [-h] a b\n\npositional arguments:\n  a           |int|\n  b           |int|\n\noptional arguments:\n  -h, --help  show this help message and exit\n```\n\nthus:\n\n    pascal@archbook:~/calc$ calc add 1 10\n    11\n\n#### Installation of commands\n\nYou noticed we ran\n\n    cliche install calc\n\nWe can undo this with\n\n    cliche uninstall calc\n\nNote that installing means that all `@cli` functions will be detected\nin the folder, not just of a single file, even after installation. You\nonly have to install once, and on Linux it also adds autocompletion to\nyour CLI if `argcomplete` has been installed.\n\n#### Advanced Example\n\n```python\nfrom cliche import cli\n\n@cli\ndef add_or_mul(a_number: int, b_number=10, sums=False):\n    \"\"\" Adds or multiplies a and b\n\n    :param a_number: the first one\n    :param b_number: second one\n    :param sums: Sums when true, otherwise multiply\n    \"\"\"\n    if sums:\n        print(a_number + b_number)\n    else:\n        print(a_number * b_number)\n```\n\nHelp:\n\n![cliche rendered](./resources/cliche_rendered.png)\n\nCalling it:\n\n    pascal@archbook:~/calc$ calc add_or_mul 1\n    10\n\n    pascal@archbook:~/calc$ calc add_or_mul --sum 1\n    11\n\n    pascal@archbook:~/calc$ calc add_or_mul 2 -b 3\n    6\n\n#### More examples\n\nCheck the example files [here](https://github.com/kootenpv/cliche/tree/master/examples)\n\n## Comparison with other CLI generators\n\n  - argparse: it is powerful, but you need a lot of code to construct an argparse CLI\n  - click: you need a lot of decorators to construct a CLI, and not obvious how to use it. It does not keep things DRY. Also, the annotated function is not usable.\n  - hug (cli): connected to a whole web framework, but gets a lot right\n  - python-fire: low set up, but annoying traces all the time / ugly design, does not show default values nor types\n  - cleo: requires too much code/objects to construct\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkootenpv%2Fcliche","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkootenpv%2Fcliche","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkootenpv%2Fcliche/lists"}