https://github.com/kaliv0/chancleta
Python library for creating Command Line Interfaces via configuration files
https://github.com/kaliv0/chancleta
command-line-interface json python-cli-starter-kit toml xml yaml
Last synced: 3 months ago
JSON representation
Python library for creating Command Line Interfaces via configuration files
- Host: GitHub
- URL: https://github.com/kaliv0/chancleta
- Owner: kaliv0
- License: mit
- Created: 2024-09-28T10:42:09.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-13T05:23:53.000Z (about 1 year ago)
- Last Synced: 2025-04-30T05:45:17.906Z (about 1 year ago)
- Topics: command-line-interface, json, python-cli-starter-kit, toml, xml, yaml
- Language: Python
- Homepage: https://pypi.org/project/chancleta/
- Size: 2.8 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# chancleta

[](https://pypi.org/project/chancleta/)
[](https://pepy.tech/projects/chancleta)
Python library for creating command line interfaces in a composable way via configuration files.
Supports .toml, .json, .yaml. and (if you'd like to be more adventurous) .xml.
---------------------------
### How to use
- Describe configurations in a chancleta.toml file.
(File format could vary between .toml, .json, .yaml and .xml as long as the name remains the same.)
Add mandatory 'meta' data with general information about your program
```toml
[meta]
src = "testoo.util.commands"
prog = "foo"
version = "0.1.0"
description = "Test my new flip flops"
usage = "Take that jive Jack, put it in your pocket 'til I get back"
```
'src' points to the directory where the corresponding python functions are to be found and called with arguments read from the terminal
- Configure subcommands as separate tables (objects if you're using JSON)
```toml
[yes]
description = "Simple yes function"
argument = { name = "text", help = "Some dummy text" }
option = { name = "should-repeat", short = "r", flag = "True", help = "should repeat text 5 times" }
help = "yes func"
function = "yes"
```
function shows the name of the python function to be called
- If you have multiple arguments/options - put them as inline tables inside arrays
```toml
[echo]
arguments = [
{ name = "text", help = "Some dummy text" },
{ name = "mark", type = "str", help = "Final mark" },
]
options = [
{ name = "other-text", short = "o", default = "Panda", dest = "other", help = "Some other dummy text" },
{ name = "delimiter", default = ", ", help = "use DELIM instead of TAB for field delimiter" },
{ name = "num", default = 42, type = "int", help = "some random number to make things pretty" }
]
function = "echo"
```
chancleta supports advanced features such as choices, nargs, dest (for options), type validation
```toml
[maybe]
argument = { name = "number", type = "int", choices = [3, 5, 8], help = "Some meaningless number" }
option = { name = "other-number", type = "int", nargs = "*", choices = [1, 2], dest = "other", help = "Other marvelous number" }
function = "maybe"
```
- For boolean flags you could use
```toml
options = [
{ name = "should-log", flag = "False", default = true },
{ name = "should-repeat", flag = "True"}
]
```
which is equivalent to
```
action="store_false"...
action="store_true"...
```
- If no short name is given for an option, the first letter of the full name is used
---------------------------
- Inside your program import the Chancleta object, pass a path to the directory where your config file lives and call the parse method
```python
from chancleta import Chancleta
def main():
Chancleta("./testoo/config").parse()
```
If no path is given chancleta will try to find the config file inside the root directory of your project