fwkz / riposte Goto Github PK
View Code? Open in Web Editor NEWPython package for wrapping applications inside a tailored interactive shell
License: MIT License
Python package for wrapping applications inside a tailored interactive shell
License: MIT License
readline prevents compatibility with Windows; pyreadline could be used as a drop-in replacement with a conditional import
Following code
from riposte import Riposte
mainrepl = Riposte(prompt="repl:~$ ")
DATA = []
@mainrepl.command("add")
def add(x: str):
DATA += x
@mainrepl.command("get")
def get():
mainrepl.success(DATA)
mainrepl.run()
Gives me
$python3 riposte_test.py
repl:~$ add foo
Traceback (most recent call last):
File "riposte_test.py", line 15, in <module>
mainrepl.run()
File "/home/user/.local/lib/python3.7/site-packages/riposte/riposte.py", line 241, in run
self._process()
File "/home/user/.local/lib/python3.7/site-packages/riposte/riposte.py", line 228, in _process
self._get_command(command_name).execute(*args)
File "/home/user/.local/lib/python3.7/site-packages/riposte/command.py", line 106, in execute
return self._func(*self._apply_guides(self._bind_arguments(*args)))
File "riposte_test.py", line 9, in add
DATA += x
UnboundLocalError: local variable 'DATA' referenced before assignment
Any class methods (for example, “assign” to a list) works fine.
Am I missing something? I can't find answer in docs.
$python3 -V
Python 3.7.3rc1
For command completion when there's only one possibility the auto-completer should automatically add a space at the end.
This looks like a convenient tool! I'm curious what support it has for asyncio and if it doesn't have it, perhaps this could be an feature request asking for it.
Would it be possible to add a default command option? I'm running into a situation where I'd like to have a default command case be shelling out to a remote server.
This could be represented as a decorator like:
@shell.default
def shell_out(command: str):
remote.execute(command)
Would it be feasible (and sensical) to implement a per-command switch to specify parsing mode? In some instances it would be helpful to be able to process command arguments as raw rather than parsed tokenized strings (or even as string literals), including preserving double and single quotes. I mean something like the difference between the two commands in this fabricated example:
riposte ~$ echo "This is a string literal"
This is a string literal
riposte ~$ raw "This" 'is' a 'raw' "string"
"This" 'is' a 'raw' "string"
shlex.split()'s posix argument seems like it might be part of a solution. Ideally the mode switch could be available as a parameter when declaring a Command, or perhaps as part of guides
?
A good solution would be implementing a switch that is similar to python -c "import foo; foo.bar()" so we could leave the option of state manipulation open ./custom_shell -c "set foo 123; set bar 456; baz"
Reference https://www.reddit.com/r/Python/comments/c8s6al/wrap_your_application_inside_a_tailored/esq2kc2/
README.md mentions CONTRIBUTING.md in the Contributing section, but that file is not in the repo and the link leads to a 404
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.