{
"info": {
"author": "Ahmad Anondo",
"author_email": "aanondos@gmail.com",
"bugtrack_url": null,
"classifiers": [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3"
],
"description": "Pikli: Library For Making CLI Apps\n==================\n\n[](https://travis-ci.org/Anondo/pikli)\n[](https://github.com/Anondo/pikli/blob/master/LICENSE)\n[](https://github.com/Anondo/pikli/releases)\n[](https://www.python.org/downloads/release/python-370/)\n\nA simple python library to build command-line interfaces. Heavily inspired by [Cobra](https://github.com/spf13/cobra.git).\n\n## Installing\n\n```\npip install pikli\n```\n\n## Getting Started\n\nPikli is a command line parser. It parses the arguments provided on the command prompt & decides whether its a command or a flag or an argument for a command & acts accordingly. A command may have: Flags , Arguments & Sub Commands. In the following example:\n\n```python\n\n#main.py\n\nimport pikli\n\ndef start_server(arg):\n print(\"HTTP server running\")\n\nroot = pikli.Command(use = \"hello\" , short = \"hello is a cli app\")\n\nserve = pikli.Command(use = \"serve\" , short = \"starts the http server\",\n\n run = start_server\n )\n\nroot.add_command(serve)\n\nroot.execute()\n\n\n\n```\nWe have two commands ```root``` & ```serve```. ```root``` as its name suggests is the root command. This decision is made by providing a parent-child relationship. Its basically a tree like structure. And the command which sits at the top of the tree is the root. The ```serve``` command is made a sub/child command of ```root``` by the ```add_command``` method of the ```Command``` class.The ```add_command``` method takes arbitrary amount of commands to add as a ```sub command```. And ```execute``` does exactly what it looks like, executes the command. Now onto the parameters provided while creating the objects:
\n**```use```**: Determines the name of the command. Mandatory.
\n**```short```**: A short description of the command.
\n**```long```**: A long description of the command.
\n**```run```**: The function which is triggered when the ```execute``` method of a command is called. There is a thing to remember about the ```run``` funtion. The function which is to be used as the ```run``` function(in this case **start_server**), **must have a single parameter which will be used as a list.**.\n\n### Flags\n\nFlags are extra options used with a command. For example: ```git commit -m \"Initial Commit\"``` here, **git** is the **root command**, **commit** is the **sub command**, **-m** is the ``flag`` & the string after that is its value. Now lets see a pikli example:\n\n```python\nimport pikli\n\ndef start_server(arg):\n print(\"HTTP server running on port: {}\".format(pikli.get_int(\"port\")))\n\nroot = pikli.Command(use = \"hello\" , short = \"hello is a cli app\")\n\nserve = pikli.Command(use = \"serve\" , short = \"starts the http server\",\n\n run = start_server\n )\n\nserve.flags().intp(\"port\" , \"p\" , 8000 , \"the port on which the server runs\")\n\nroot.add_command(serve)\n\nroot.execute()\n\n```\nThe ```flags``` method of a ```Command``` returns the ```flag``` object that handles every flag related activity for the command. ```intp``` is a method of that object which creates an ```integer flag```.There is also ```stringp``` & ```boolp```. The first parameter is the name of the flag(used in the long version), the second one is the usable name of the flag like, ```-p```. The third parameter is the default value for the flag. There is no default value for the bool flag. Its False by default. And the fourth one should be obvious, a description of the flag. Now lets use everything we have seen so far:
\n```\npython main.py serve -p 8080\n```\n
\n\n or\n\n
\n\n ```\n python main.py serve --port=8080\n ```\n
\nThe output should be:
\n\n```\nHTTP server running on port: 8080\n```\n
\n\nExecuting the serve command without the ```p``` flag will return the default value when ```pikli.get_int(\"port\")``` is called which is a pikli core function used for retrieving the value of an integer flag. Similarly there are ```get_str``` & ```get_bool``` to get **string** & **bool** flag values.\n\n### The Help Flag\n\n**Pikli** provides an automatic help flag generation & recognition. Whenever a ```command``` without a ```run``` function is executed, the ```help``` flag will be executed autmatically. Or, it can be explicitly mentioned like any other flag like ```-h``` or ```--help```. Try:
\n```\npython main.py serve --help\n```\n
\n\nSimply running ```python main.py``` will trigger its help flag as it has no ```run``` function. A help flag should display something similar:
\n```\nhello is a cli app\n\n\nUsage:\n\thello [args] [flags] [sub commands]\n\n\nAvailable Commands:\nserve starts the http server\n\n\nFlags:\n-h, --help Shows info regarding the command\n```\n\n### The Persistent Flag\n\n**Pikli** provides support for ```persistent flags```. ```Persistent flags``` are like normal ```flags``` except if you assign it to a ```command``` it automatically gets assigned to every child it has upto the bottom of the ```command``` tree. So if a ```persistent flag``` is assigned to the ```root command``` then every ```command``` will get that ```flag```.
\n\n```python\nimport pikli\n\ndef start_server(arg):\n if pikli.get_bool(\"verbose\"):\n print(\"showing details\")\n print(\"HTTP server running on port: {}\".format(pikli.get_int(\"port\")))\n\n\nroot = pikli.Command(use = \"hello\" , short = \"hello is a cli app\")\n\nserve = pikli.Command(use = \"serve\" , short = \"starts the http server\",\n\n run = start_server\n )\n\nserve.flags().intp(\"port\" , \"p\" , 8000 , \"the port on which the server runs\")\n\nroot.add_command(serve)\n\nroot.persistent_flags().boolp(\"verbose\" , \"v\" , \"shows details regarding the operation\")\n\nroot.execute()\n\n```\nHere the **verbose** ```flag``` is assigned to the ```root command``` making this flag a global one. When assigning ```persistent flags```, don't forget to add all the ```sub commands``` at first.\n\n### Args\n\nApart from ```sub commands``` & ```flags``` normal arguments can be used in **pikli**. All that is needed is the ```arg``` list that is used as the parameter of the ```run``` function. Lets see an example:
\n\n```python\nimport pikli\n\ndef greet(arg):\n print(\"Hello {}, beef cheese delight rocks\".format(arg[0]))\n\nroot = pikli.Command(use = \"hello\" , short = \"hello is a greeting app\",\n run = greet)\n\nroot.persistent_flags().boolp(\"verbose\" , \"v\" , \"shows details regarding the operation\")\n\nroot.execute()\n\n```\n
\n\nJust keep the index order of the ```arguments``` right. The index number of the ```arguments``` doesn't bother about the ```flags```. For example **``` python main.py -v \"John Doe\" ```** **pikli** will ignore the flags & count the ```argument``` **John Doe** as index 0 & so on. The output should be:
\n\n```\nHello John Doe, beef cheese delight rocks\n```\n\n### Env\n\nLastly you can get the string or integer environmental variables using **pikli**. The two functions for this are ```get_str_env``` & ```get_int_env```:
\n\n```python\nimport pikli\n\ndef greet(arg):\n print(\"Hello {}, beef cheese delight rocks\".format(pikli.get_str_env(\"NAME\")))\n\nroot = pikli.Command(use = \"hello\" , short = \"hello is a greeting app\",\n run = greet)\n\nroot.execute()\n\n```\n\n
\n\nRun it like this:
\n```\nNAME=\"John Doe\" python main.py\n```\n\n## Contributing\nTotally open to suggestions. [See the contribution guide](https://github.com/Anondo/pikli/blob/master/CONTRIBUTING.md)\n\n## License\n\nPikli is licensed under the [MIT License](https://github.com/Anondo/pikli/blob/master/LICENSE)",
"description_content_type": "text/markdown",
"docs_url": null,
"download_url": "",
"downloads": {
"last_day": -1,
"last_month": -1,
"last_week": -1
},
"home_page": "https://github.com/Anondo/pikli",
"keywords": "",
"license": "",
"maintainer": "",
"maintainer_email": "",
"name": "pikli",
"package_url": "https://pypi.org/project/pikli/",
"platform": "",
"project_url": "https://pypi.org/project/pikli/",
"project_urls": {
"Homepage": "https://github.com/Anondo/pikli"
},
"release_url": "https://pypi.org/project/pikli/1.0/",
"requires_dist": null,
"requires_python": "",
"summary": "A library to create cli apps",
"version": "1.0"
},
"last_serial": 4643753,
"releases": {
"1.0": [
{
"comment_text": "",
"digests": {
"md5": "ded5e81093194389997d900fea79f683",
"sha256": "3456b06421d7be30c2784232b42ee5e4dfa5df7ae438b1fc067a465daece515e"
},
"downloads": -1,
"filename": "pikli-1.0.tar.gz",
"has_sig": false,
"md5_digest": "ded5e81093194389997d900fea79f683",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 11668,
"upload_time": "2018-12-29T10:43:03",
"url": "https://files.pythonhosted.org/packages/9e/3e/ef91eb8375aae0a68ec2979e2789de9c848745f83f4752b6f4d5bf176ee1/pikli-1.0.tar.gz"
}
]
},
"urls": [
{
"comment_text": "",
"digests": {
"md5": "ded5e81093194389997d900fea79f683",
"sha256": "3456b06421d7be30c2784232b42ee5e4dfa5df7ae438b1fc067a465daece515e"
},
"downloads": -1,
"filename": "pikli-1.0.tar.gz",
"has_sig": false,
"md5_digest": "ded5e81093194389997d900fea79f683",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 11668,
"upload_time": "2018-12-29T10:43:03",
"url": "https://files.pythonhosted.org/packages/9e/3e/ef91eb8375aae0a68ec2979e2789de9c848745f83f4752b6f4d5bf176ee1/pikli-1.0.tar.gz"
}
]
}