~lindsay/elapid

cli arguments parser
change the way parse arguments
fix bug bring by commit 373286d
remove custom exceptions

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~lindsay/elapid
read/write
git@git.sr.ht:~lindsay/elapid

You can also use your local clone with git send-email.

#elapid

A simple cli parser inspire by cobra

#Quick start

#!/bin/env python3
from typing import Optional
from elapid import Command

def main():
    def run (cmd: Command, args: list[str]):
        print(f'hello {cmd.flags.get("name", "")}')
    cmd = Command(use='demo [command]', short='quick demonstration')
    cmd.addFlag('-n', '--name', type=Optional[str], default='')
    hi_cmd = Command(use='hello [flags]', short='hello command', run=run)
    bye_cmd = Command(use='bye [flags]', short='bye command', run=lambda cmd, args:print(f'bye {cmd.flags.get("name", "")}'))
    cmd.addCommand(hi_cmd)
    cmd.addCommand(bye_cmd)
    cmd.execute()

if __name__ == '__main__':
    main()
(elapid) lindsay@Reisen> ./demo.py
quick demonstration

Usage:
	demo [command]

Available Commands:
	bye                 bye command
	hello               hello command

Flags:
	-n  --name str   

(elapid) lindsay@Reisen> ./demo.py -n Lindsay hello
hello Lindsay
(elapid) lindsay@Reisen> ./demo.py -n Lindsay bye
bye Lindsay