{"id":24149059,"url":"https://github.com/sanmeet007/cliopts","last_synced_at":"2025-06-30T15:36:32.419Z","repository":{"id":174113951,"uuid":"651794529","full_name":"Sanmeet007/cliopts","owner":"Sanmeet007","description":"The cliopts package is a Python library for parsing command line arguments. It provides a simpler and more intuitive API with less code and easy cli argument parsing.","archived":false,"fork":false,"pushed_at":"2024-07-28T16:58:13.000Z","size":43,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-29T18:09:42.446Z","etag":null,"topics":["cli","cliopts","command-line-parser","pyton"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/cliopts/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Sanmeet007.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["Sanmeet007"]}},"created_at":"2023-06-10T05:44:50.000Z","updated_at":"2024-07-28T16:25:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"c050c2bb-5424-45a2-a74a-422ed4fc9723","html_url":"https://github.com/Sanmeet007/cliopts","commit_stats":null,"previous_names":["sanmeet007/cliargs"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/Sanmeet007/cliopts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sanmeet007%2Fcliopts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sanmeet007%2Fcliopts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sanmeet007%2Fcliopts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sanmeet007%2Fcliopts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sanmeet007","download_url":"https://codeload.github.com/Sanmeet007/cliopts/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sanmeet007%2Fcliopts/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262801627,"owners_count":23366598,"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","cliopts","command-line-parser","pyton"],"created_at":"2025-01-12T08:35:05.840Z","updated_at":"2025-06-30T15:36:32.395Z","avatar_url":"https://github.com/Sanmeet007.png","language":"Python","funding_links":["https://github.com/sponsors/Sanmeet007"],"categories":[],"sub_categories":[],"readme":"# Cliopts Library\n\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/cliopts)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/cliopts)\n\nThe Cliopts Library is a Python library designed to simplify the process of parsing command-line arguments. It provides a straightforward and intuitive API, reducing the amount of code required for CLI argument parsing.\n\n## Installation\n\nTo install the Cliopts Library, run the following command in your terminal (cmd, bash, PowerShell, etc.):\n\n```bash\npip install cliopts\n```\n\n## Usage\n\nTo use the library in your code, follow these steps:\n\n1. Import the `CliArguments` class from the `cliopts` module:\n\n   ```python\n   from cliopts import CliArguments\n   ```\n\n2. Create an instance of `CliArguments` and pass a list of argument names or a dictionary of argument names and their shorthand notations, along with optional parameters such as `options_desc` and `version`.\n\n   Using a list of options:\n\n   ```python\n   args = CliArguments(\n       options=[\"filename\", \"count\", \"verbose\"],\n       options_desc={\n           \"filename\": \"Specify the filename\",\n           \"count\": \"Specify the count\",\n           \"verbose\": \"Enable verbose output\"\n       },\n       version=\"v1.0.0\"\n   )\n   ```\n\n   Using a dictionary of options with shorthand notations:\n\n   ```python\n   args = CliArguments(\n       options={\n           \"filename\": \"f\",\n           \"count\": \"c\",\n           \"verbose\": \"v\"\n       },\n       options_desc={\n           \"filename\": \"Specify the filename\",\n           \"count\": \"Specify the count\",\n           \"verbose\": \"Enable verbose output\"\n       },\n       version=\"v1.0.0\"\n   )\n   ```\n\n3. Access the parsed command-line arguments as a dictionary using the `to_dict()` method:\n\n   ```python\n   print(args.to_dict())\n   ```\n\n   The `to_dict()` method returns a dictionary containing the parsed arguments.\n\n4. Run your Python script and pass command-line arguments using the specified options and their shorthand notations:\n\n   ```bash\n   py test.py --filename=\"filename.txt\" --count=5 --verbose=True\n   py test.py -f \"filename.txt\" -c 5 -v True\n   ```\n\n   Replace `test.py` with the name of your script file and `filename.txt` with the desired value for the argument.\n\n### Example\n\nLet's consider an example to illustrate how to use the Cliopts Library. Suppose we are creating a Python script that takes a filename, count, and a verbose flag as input from the command line.\n\nIn `script.py` file:\n\n```python\nfrom cliopts import CliArguments\n\n# Define the desired arguments: filename, count, verbose\nargs = CliArguments(\n    options={\n        \"filename\": \"f\",\n        \"count\": \"c\",\n        \"verbose\": \"v\"\n    },\n    options_desc={\n        \"filename\": \"Specify the filename\",\n        \"count\": \"Specify the count\",\n        \"verbose\": \"Enable verbose output\"\n    },\n    version=\"v1.0.0\"\n)\n\nprint(args.to_dict())\n```\n\nIn the command line:\n\n```bash\npy script.py --filename='/files/filename.txt' --count=5 --verbose=True\npy script.py -f '/files/filename.txt' -c 5 -v True\n```\n\nThe output of `args.to_dict()` will be:\n\n```python\n{\n    \"filename\": \"/files/filename.txt\",\n    \"count\": 5,\n    \"verbose\": True\n}\n```\n\n## CliArgument class params\n\n### options\n\n- **Type**: `Iterable[str] | dict[str, str]`\n- **Description**: A list or dictionary of command-line options. If using a dictionary, the keys are the full option names and the values are their shorthand notations.\n\n### options_desc\n\n- **Type**: `dict[str, str]`\n- **Optional**: Yes\n- **Description**: A dictionary with descriptions for each option. Defaults to an empty dictionary.\n\n### version\n\n- **Type**: `str`\n- **Optional**: Yes\n- **Description**: The version of the program. Defaults to `None`.\n\n### help\n\n- **Type**: `(dict[str, str]) -\u003e Any`\n- **Optional**: Yes\n- **Description**: A function to display help information. This function takes `options_desc` as its argument. If not provided, the default help function is triggered utilizing `options_desc`.\n\n### throw_on_invalid_args\n\n- **Type**: `bool`\n- **Optional**: Yes\n- **Description**: Whether to throw an error on invalid arguments. Defaults to `True`.\n\n### name\n\n- **Type**: `str`\n- **Optional**: Yes\n- **Description**: The name of the program. Defaults to `\"python-program\"`.\n\n### desc\n\n- **Type**: `str`\n- **Optional**: Yes\n- **Description**: The description of the program. Defaults to `None`.\n\n## Default Help Function Output\n\nIf the `--help` flag is used, the default help function displays the following information:\n\n```\nUsage: python-program [options]\n\nOptions:\n    filename : Specify the filename\n    count : Specify the count\n    verbose : Enable verbose output\n\n--version : Show version\n```\n\n## Attach Version\n\nIf you want your script to return a version number when prompted with `--version`, you can easily achieve that by passing a version string as the `version` parameter when creating an instance of `CliArguments`.\n\nExample in `script.py` file:\n\n```python\nfrom cliopts import CliArguments\n\nargs = CliArguments(\n    options=[\"filename\", \"count\", \"verbose\"],\n    version=\"v1.0.0\"\n)\n```\n\nYou can now check the script version using the following command:\n\n```bash\npy script.py --version\n```\n\nThe output will be `v1.0.0`, matching the version parameter.\n\n## Contact the Developer\n\nFor any inquiries or assistance, you can contact the developer at \u003cssanmeet123@gmail.com\u003e. Feel free to reach out with any questions or feedback you may have.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanmeet007%2Fcliopts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsanmeet007%2Fcliopts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanmeet007%2Fcliopts/lists"}