-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default command option #19
Comments
Hello @nbulischeck! What would such default command do? Can you elaborate on your use-case? So in terms of the user experiance you'd like to just type "foo bar baz" and automagically point it to default_command instead of providing "default_command foo bar baz"? |
@fwkz The default command would run if a user supplied some input that did not match any currently registered commands. My current use case is remote server management where a user would be able to interact with the remote server as if they were using a normal command shell. I believe you got it correct in your example. I mocked up a quick example below. from os import system
from riposte import Riposte
class Application:
def __init__(self):
self.module = None
def exec_required(fn):
def wrapper(*args, **kwargs):
if app.module:
return fn(*args, **kwargs)
return wrapper
class CustomRiposte(Riposte):
@property
def prompt(self):
if app.module:
return f"foo:{app.module} > "
return self._prompt
app = Application()
shell = CustomRiposte(prompt="foo > ")
HISTORY = []
@shell.command("exit")
def exit():
if app.module:
app.module = None
else: quit()
@shell.command("exec")
def execute():
app.module = "PS"
@shell.command("upload")
def test():
print("Upload")
@shell.command("history")
def history():
for entry in HISTORY:
shell.print(entry)
@shell.command("default")
@exec_required
def default(command: str):
system(command)
HISTORY.append(command)
shell.run() The user first enters Edit: As an afterthought, would it be possible to switch between multiple riposte shells? |
You can easily nest multiple shells, creating "riposte inception". Just remember to give each instance it's own But something like |
How does the idea of a default command sound? @shell.default
@exec_required
def default(command: str):
system(command)
HISTORY.append(command) |
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:
The text was updated successfully, but these errors were encountered: