cliopts


Namecliopts JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/Sanmeet007/cliopts.git
SummaryThe 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.
upload_time2023-06-10 06:40:26
maintainer
docs_urlNone
authorSanmeet Singh
requires_python
licenseGPL-3.0 license
keywords python command line command line arguments cli cli args cli opts command line options cliargs argparser
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Cliopts Library



The 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.



## Installation



To install the Cliopts Library, run the following command in your terminal (cmd, bash, powershell, etc.):



```bash

pip install cliopts

```



## Usage



To use the library in your code, follow these steps:



1. Import the `CliArguments` class from the `cliopts` module:



   ```python

   from cliopts import CliArguments

   ```



2. Create an instance of `CliArguments` and pass a list of argument names as a parameter:



   ```python

   args = CliArguments(["options"])

   ```



3. Access the parsed command line arguments as a dictionary using the `todict()` method:



   ```python

   print(args.todict())

   ```



   The `todict()` method returns a dictionary containing the parsed arguments.



4. Run your Python script and pass command line arguments using the specified options:



   ```bash

   py test.py --filename="filename"

   py test.py -f filename

   py test.py --f="filename"

   ```



   Replace `test.py` with the name of your script file and `filename` with the desired value for the argument.



### Example



Let's consider an example to illustrate how to use the cliopts Library. Suppose we are creating a Python script that takes a filename as input from the command line.



In `script.py` file:



```python

from cliopts import CliArguments



# Define the desired arguments: filepath, count, boolean

args = CliArguments(["filepath", "count", "boolean"]) 



print(args.todict())

```



In the command line:



```bash

py script.py -f '/files/filename.txt' -c 5 -b True 

```



The output of `args.todict()` will be:



```python

{

    "filepath": "/files/filename.txt",

    "count" : 5,

    "boolean": True

}

```



## Attach Version



If 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 second parameter when creating an instance of `CliArguments`.



Example in `script.py` file:



```python

from cliopts import CliArguments



args = CliArguments(["options"], "v1.0.0")

```



You can now check the script version using the following command:



```bash

py script.py --version

```



The output will be `v1.0.0`, matching the second parameter.



## Attach Help Function



If you want your script to run a help program  when prompted with `--help`, you can easily achieve that by passing a help_function , callable as the third parameter when creating an instance of `CliArguments`.



Example in `script.py` file:



```python

from cliopts import CliArguments



def help_function(): 

   print("HELP STRING")



args = CliArguments(["options"], "v1.0.0"  , help_function)

```



You can now run a help function using the following command:



```bash

py script.py --help

```



The output will be `HELP STRING`, matching the output of function passed as third parameter.



## Contact the Developer



For any inquiries or assistance, you can contact the developer at <ssanmeet123@gmail.com>. Feel free to reach out with any questions or feedback you may have.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Sanmeet007/cliopts.git",
    "name": "cliopts",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python,command line,command line arguments,cli,cli args,cli opts,command line options,cliargs,argparser",
    "author": "Sanmeet Singh",
    "author_email": "ssanmeet123@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/5e/70/df9bd33d0dc71f6b82b2ccc27202c1086577cbe171e4db762e737c108dc0/cliopts-1.0.1.tar.gz",
    "platform": null,
    "description": "\r\n# Cliopts Library\r\n\r\n\r\n\r\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.\r\n\r\n\r\n\r\n## Installation\r\n\r\n\r\n\r\nTo install the Cliopts Library, run the following command in your terminal (cmd, bash, powershell, etc.):\r\n\r\n\r\n\r\n```bash\r\n\r\npip install cliopts\r\n\r\n```\r\n\r\n\r\n\r\n## Usage\r\n\r\n\r\n\r\nTo use the library in your code, follow these steps:\r\n\r\n\r\n\r\n1. Import the `CliArguments` class from the `cliopts` module:\r\n\r\n\r\n\r\n   ```python\r\n\r\n   from cliopts import CliArguments\r\n\r\n   ```\r\n\r\n\r\n\r\n2. Create an instance of `CliArguments` and pass a list of argument names as a parameter:\r\n\r\n\r\n\r\n   ```python\r\n\r\n   args = CliArguments([\"options\"])\r\n\r\n   ```\r\n\r\n\r\n\r\n3. Access the parsed command line arguments as a dictionary using the `todict()` method:\r\n\r\n\r\n\r\n   ```python\r\n\r\n   print(args.todict())\r\n\r\n   ```\r\n\r\n\r\n\r\n   The `todict()` method returns a dictionary containing the parsed arguments.\r\n\r\n\r\n\r\n4. Run your Python script and pass command line arguments using the specified options:\r\n\r\n\r\n\r\n   ```bash\r\n\r\n   py test.py --filename=\"filename\"\r\n\r\n   py test.py -f filename\r\n\r\n   py test.py --f=\"filename\"\r\n\r\n   ```\r\n\r\n\r\n\r\n   Replace `test.py` with the name of your script file and `filename` with the desired value for the argument.\r\n\r\n\r\n\r\n### Example\r\n\r\n\r\n\r\nLet's consider an example to illustrate how to use the cliopts Library. Suppose we are creating a Python script that takes a filename as input from the command line.\r\n\r\n\r\n\r\nIn `script.py` file:\r\n\r\n\r\n\r\n```python\r\n\r\nfrom cliopts import CliArguments\r\n\r\n\r\n\r\n# Define the desired arguments: filepath, count, boolean\r\n\r\nargs = CliArguments([\"filepath\", \"count\", \"boolean\"]) \r\n\r\n\r\n\r\nprint(args.todict())\r\n\r\n```\r\n\r\n\r\n\r\nIn the command line:\r\n\r\n\r\n\r\n```bash\r\n\r\npy script.py -f '/files/filename.txt' -c 5 -b True \r\n\r\n```\r\n\r\n\r\n\r\nThe output of `args.todict()` will be:\r\n\r\n\r\n\r\n```python\r\n\r\n{\r\n\r\n    \"filepath\": \"/files/filename.txt\",\r\n\r\n    \"count\" : 5,\r\n\r\n    \"boolean\": True\r\n\r\n}\r\n\r\n```\r\n\r\n\r\n\r\n## Attach Version\r\n\r\n\r\n\r\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 second parameter when creating an instance of `CliArguments`.\r\n\r\n\r\n\r\nExample in `script.py` file:\r\n\r\n\r\n\r\n```python\r\n\r\nfrom cliopts import CliArguments\r\n\r\n\r\n\r\nargs = CliArguments([\"options\"], \"v1.0.0\")\r\n\r\n```\r\n\r\n\r\n\r\nYou can now check the script version using the following command:\r\n\r\n\r\n\r\n```bash\r\n\r\npy script.py --version\r\n\r\n```\r\n\r\n\r\n\r\nThe output will be `v1.0.0`, matching the second parameter.\r\n\r\n\r\n\r\n## Attach Help Function\r\n\r\n\r\n\r\nIf you want your script to run a help program  when prompted with `--help`, you can easily achieve that by passing a help_function , callable as the third parameter when creating an instance of `CliArguments`.\r\n\r\n\r\n\r\nExample in `script.py` file:\r\n\r\n\r\n\r\n```python\r\n\r\nfrom cliopts import CliArguments\r\n\r\n\r\n\r\ndef help_function(): \r\n\r\n   print(\"HELP STRING\")\r\n\r\n\r\n\r\nargs = CliArguments([\"options\"], \"v1.0.0\"  , help_function)\r\n\r\n```\r\n\r\n\r\n\r\nYou can now run a help function using the following command:\r\n\r\n\r\n\r\n```bash\r\n\r\npy script.py --help\r\n\r\n```\r\n\r\n\r\n\r\nThe output will be `HELP STRING`, matching the output of function passed as third parameter.\r\n\r\n\r\n\r\n## Contact the Developer\r\n\r\n\r\n\r\nFor any inquiries or assistance, you can contact the developer at <ssanmeet123@gmail.com>. Feel free to reach out with any questions or feedback you may have.\r\n\r\n",
    "bugtrack_url": null,
    "license": "GPL-3.0 license",
    "summary": "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.",
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://github.com/Sanmeet007/cliopts.git"
    },
    "split_keywords": [
        "python",
        "command line",
        "command line arguments",
        "cli",
        "cli args",
        "cli opts",
        "command line options",
        "cliargs",
        "argparser"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5bea13b8ce16d26c7ba9188cac780c0a7431225148e8b32185dba0b5211735be",
                "md5": "449b2c3a6aa5b4989293525f057f1db8",
                "sha256": "ed40a015ae1793698151bdb27d18699aecc897af035cdf246628208b5afc8dd4"
            },
            "downloads": -1,
            "filename": "cliopts-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "449b2c3a6aa5b4989293525f057f1db8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 16588,
            "upload_time": "2023-06-10T06:40:23",
            "upload_time_iso_8601": "2023-06-10T06:40:23.633907Z",
            "url": "https://files.pythonhosted.org/packages/5b/ea/13b8ce16d26c7ba9188cac780c0a7431225148e8b32185dba0b5211735be/cliopts-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5e70df9bd33d0dc71f6b82b2ccc27202c1086577cbe171e4db762e737c108dc0",
                "md5": "57275fbf9913616e99599a67a0cecaf5",
                "sha256": "e79445e9226bcf5ba3df2e1f385a41a91d421fab2f5d94dcaef4aba357d6dbd3"
            },
            "downloads": -1,
            "filename": "cliopts-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "57275fbf9913616e99599a67a0cecaf5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 15660,
            "upload_time": "2023-06-10T06:40:26",
            "upload_time_iso_8601": "2023-06-10T06:40:26.074021Z",
            "url": "https://files.pythonhosted.org/packages/5e/70/df9bd33d0dc71f6b82b2ccc27202c1086577cbe171e4db762e737c108dc0/cliopts-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-10 06:40:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Sanmeet007",
    "github_project": "cliopts",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "cliopts"
}
        
Elapsed time: 0.08445s