{"id":20431488,"url":"https://github.com/devyatsu/command_liner","last_synced_at":"2026-05-28T20:31:01.967Z","repository":{"id":176947515,"uuid":"659770820","full_name":"DevYatsu/command_liner","owner":"DevYatsu","description":"A simple template to create a CLI (command line interface) made in python.","archived":false,"fork":false,"pushed_at":"2023-07-03T21:03:13.000Z","size":48,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-05T05:44:53.358Z","etag":null,"topics":[],"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/DevYatsu.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":"2023-06-28T14:20:22.000Z","updated_at":"2023-06-29T17:33:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"ae5b5783-ff8c-4b07-80d0-7274082848ac","html_url":"https://github.com/DevYatsu/command_liner","commit_stats":null,"previous_names":["devyatsu/command_liner"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/DevYatsu/command_liner","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevYatsu%2Fcommand_liner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevYatsu%2Fcommand_liner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevYatsu%2Fcommand_liner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevYatsu%2Fcommand_liner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DevYatsu","download_url":"https://codeload.github.com/DevYatsu/command_liner/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevYatsu%2Fcommand_liner/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33626136,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-28T02:00:06.440Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-15T08:12:01.126Z","updated_at":"2026-05-28T20:31:01.922Z","avatar_url":"https://github.com/DevYatsu.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# command_liner\nA simple template to create a CLI (command line interface) made in python.\n\n## Project purpose\nThe purpose of this project is rather simple. I wanted to share a simple way for python developers to create customizable command line interfaces. The concept here is not necessarily to create a line interface usable for everyone... it's to create a line interface usable by whoever has python installed on his computer. It could be rather simple to implement it for every computer on earth by generating an exetuble but it was not my intention here. \n\n## Prerequisites\nTo use command_liner, it should be a piece of cake if you know some python. \nYou need python installed on your device to use the project.\n\n### Copy the project\nRun  `git clone https://github.com/DevYatsu/command_liner` \n\n### Project infrastructure\nYou should find 7 files in this project:\n- .gitignore\n- command_liner.py\n- command.py\n- exceptions.py\n- LICENSE\n- commands.py\n- initializer.py\n- main.py\n- README.md\n\nYou at least need the *.py* files to use command_liner. \n\n### Fundamentals\n- **command.py** contains all the code regarding the creation of the command class\n- **command_liner.py** contains code on the commands_wrapper class\n- **exceptions.py** contains code regarding errors managing\n- **commands.py** contains all the commands usable with the CLI\n- **initializer.py** contains the project config, that is the name of the CLI\n- **main.py** contains the code necessary to run the CLI\n\nYou can look at all the files to understand the logic of the project, and modify them if necessary. However if you need a simple use of command_liner just open **initializer.py**, **main.py** and **commands.py** in your code editor.\n\nOn **initializer.py** file, set `commands_prefix` variable to whichever name you want to give to your client, it's the prefix you want to call your comands with.\n\nThen, you can take a look at the commands and understand how to create them in **commands.py**, actually, it is rather simple, it's done in a few steps only:\n1. Init a command instance with two arguments, its name and its description\n2. You can also set description separately with `.set_description()`, description will be displayed when running `command_name --description`\n3. Set a helper message with `.set_help()`, will be displayed when running `command_name --help`\n4. Add parameters with `.add_parameter()` or `.add_params()` methods, these params are needed when running the command\n5. Add **optional** parameters with `.add_optional_parameter()` or `.add_optional_params()` methods, can be add after the required ones when running the command\n6. Use `.set_script()` to write the script run on command use, takes as first parameter the script to run and as others the parameters to use in the script, set them here in the position you want them to be called when using the command\n\nWhen you're done with creating your commands, import them in **main.py** and add them in `commands` list.\n\n### Example\n\nLet's see a simple example of a command definition, we will suppose that all theimports are doeand that the client is generated\n\n``` python\n### in commands.py\n\n# first we create the command\nexample_command = Command(\"example\", \"An example command.\")\n\n# set help message\nexample_command = example_command.set_help(\n    f\"To run the command:\\n\\t* example \u003cparam1\u003e \u003cparam2\u003e\")\n\n# add parameters in command\nexample_command = example_command.add_params(\"param1\", \"param2\")\n\n# add optional params\nexample_command = example_command.add_optional_parameter(\"param3\")\n\nexample_command = example_command.set_script('''\nparam1 = \"+++\"\nparam2 = \"+++\"\nparam3 = \"+++\"\n\nprint(param1)  \nif param3 != \"\": # param3 is optional and set to \"\" if not add in command\n    print(param3)                                            \nprint(param2)     \nprint(param1)     \nprint(param2) \nif param3 != \"\":\n    print(param3)    \nprint(param1)     \n\n''', \"param1\", \"param2\", \"param3\")\n\n\n### in main.py\n# do not forget to put everything in commands list:\n\ncommands = list([generate_sh_command, destruct_sh_command, example_command])\n# required at least the generate_sh_command, destruct_sh_command commands to run the shell script and destroy it \n```\n\nIt's as simple as that!\n\nTo make it even simpler, put everything together:\n```python\n### in commands.py\nfrom initializer import get_prefix\nfrom command import Command\n\nexample_command = Command(\"example\", \"An example command.\").set_help(\n    f\"To run the command:\\n\\t* {get_prefix()} example \u003cparam1\u003e \u003cparam2\u003e\").add_params(\"param1\", \"param2\").add_optional_parameter(\"param3\").set_script('''\nparam1 = \"+++\"\nparam2 = \"+++\"\nparam3 = \"+++\"\n\nprint(param1)  \nif param3 != \"\": # param3 is optional and set to \"\" if not add in command\n    print(param3)                                            \nprint(param2)     \nprint(param1)     \nprint(param2) \nif param3 != \"\":\n    print(param3)    \nprint(param1)     \n```\n\nAnd if we add everything necessary to make it work...\n\n```python\n### in commands.py\nfrom initializer import get_prefix\nfrom command import Command\n\nexample_command = Command(\"example\", \"An example command.\").set_help(\n    f\"To run the command:\\n\\t* {get_prefix()} example \u003cparam1\u003e \u003cparam2\u003e\").add_params(\"param1\", \"param2\").add_optional_parameter(\"param3\").set_script('''\nparam1 = \"+++\"\nparam2 = \"+++\"\nparam3 = \"+++\"\n\nprint(param1)  \nif param3 != \"\": # param3 is optional and set to \"\" if not add in command\n    print(param3)                                            \nprint(param2)     \nprint(param1)     \nprint(param2) \nif param3 != \"\":\n    print(param3)    \nprint(param1)     \n''', \"param1\", \"param2\", \"param3\")\n\n\n## in main.py\nimport sys\nfrom commands import example_command, generate_sh_command, destruct_sh_command\nfrom initializer import command_client\n\n# put all commands here\ncommands = list([generate_sh_command, destruct_sh_command, example_command])\n\n# run the script\ncommand_client.append_commands(\n    *commands).run_command(sys.argv)\n```\n\nTa daaa! That's it!\n\n## Make it executable globally\n\nRun `python main.py generate-sh`\n\nUse the command line interface anywhere: `prefix \u003cyour commands\u003e`\n\nIf you make changes in your main.py:\n- run `prefix destroy-sh`\n- rerun `python main.py generate-sh`\n- you can restart using you CLI\n\n## LICENCE \nMIT as always...\nI hereby allow you to do whatever you want with this project!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevyatsu%2Fcommand_liner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevyatsu%2Fcommand_liner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevyatsu%2Fcommand_liner/lists"}