API Reference¶
Command Class¶
- class easycli.Command¶
Abstract base class for all commands.
- __command__ = None¶
str, command name
- __aliases__ = None¶
List of aliases for the
__command__
- __help__ = None¶
Help message to show when -h/–help
- __call__(args)¶
Execute the command.
This method should be implemented in the child class to do what the command does.
- Parameters:
args – What
argparse.ArgumentParser.parse_args()
returns.
SubCommand Class¶
- class easycli.SubCommand(subparsers)¶
Bases:
Command
Base class for sub commands.
root subcommand subsubcommand
For example, in
git push ..
scenariopush
is a sub command.Users must inherit this class and configure the sub class to create new shell sub command behavior.
from easycli import SubCommand, Root class Push(SubCommand): __command__ = 'push' __aliases__ = ['p', 'pu'] __arguments__ = [ ... ] class Git(Root): ... __arguments__ = [ Push, ... ]
Root Class¶
- class easycli.Root¶
Bases:
Command
base class for the CLI entry point.
import sys from easycli import Root, ... class Git(Root): __help__ = 'git help message' __completion__ = True __arguments__ = [ Pull, Push, Commit, ... ] if __name__ == '__main__': sys.exit(Git.quickstart())
- __completion__ = None¶
If True, a completion sub-command with two subsub-commands: install and uninstall will be added to
self.__arguments__
collection.
- main(argv=None)¶
Call this function as the main entry point for your cli application.
- Parameters:
argv – If not given,
sys.argv
will be used.- Returns:
exit status
- classmethod quickstart(argv=None)¶
Shorthand for
Root().main()
.
Argument Class¶
- class easycli.Argument(*a, completer=None, **kw)¶
Just a wrapper around
argparse.ArgumentParser.add_argument()
.So, except the
completer
keyword argument all positional and keywork arguments are the same asargparse.ArgumentParser.add_argument()
.- Parameters:
completer – see argcomplete
Mutex Class¶
- class easycli.Mutex(*args, required=False)¶
Mutually exclusive group.
New in version 1.9.
class Foo(Root): __arguments__ = [ Mutex( Argument('--bar'), Argument('--baz') ) ] ...
ProgressBar Class¶
- class easycli.ProgressBar(total)¶
Context manager to show and update progress bar.
with ProgressBar(1000) as p: for i in range(1000): ... # Step forward p.increment()