A few interface and argparse overrides to help quickly build a repl tool
Project description
ReplBuilder
pip install replbuilder
Quickly build a repl cli prompt in python.
argparse
is used for quick and easy parsing interface, some options are overriden for using it within a repl prompt. But you should be able to utilize the full power of argparse
as your repl parser.
Example
see example calculator repl for example implementation. The gist can be concluded in a few lines:
add_cmd = ReplCommand("add", Calculator.basic_parser(), calculator.add, "Add 2 numbers")
sub_cmd = ReplCommand("sub", Calculator.basic_parser(), calculator.sub, "Subtract second number from first")
mult_cmd = ReplCommand("mult", Calculator.basic_parser(), calculator.mult, "Multiply 2 numbers")
# More advanced usage with exception handler and context obj:
fact_cmd = ReplCommand("factorial", Calculator.factorial_parser(), calculator.factorial, "factorial with exception handler", exception_handler=exception_handler)
say_cmd = ReplCommand("cowsay", Cow.get_cowsay_parser(), cow.cowsay, "say stuff, demo optional and context usage", use_context=True)
mood_cmd = ReplCommand("cowmood", argparse.ArgumentParser(), cow.cowmood, "Mood of the cow changes with global context object", use_context=True)
runner = ReplRunner("calculator", context)
runner.add_commands([add_cmd, sub_cmd, mult_cmd, fact_cmd, say_cmd, mood_cmd])
runner.run()
run it python example_calculator_repl.py
Part of the repl is colorized for better visibility:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
replbuilder-0.3.0.tar.gz
(3.2 kB
view hashes)
Built Distribution
Close
Hashes for replbuilder-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3751093d1e348d30550b5f43c10cd6de5287874000d9cf3f8c17228b72c74905 |
|
MD5 | 460d3a329fa4baf3681b4ca5f8552b4e |
|
BLAKE2b-256 | 54c3ddcd76feef08a0fdb02fc79854fb8c01af70eb561d9746aef3337321d3d6 |