mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-01-25 08:23:35 +08:00
added input prompt functionality to bacloud client
This commit is contained in:
parent
5a389efb65
commit
84338018b9
@ -92,6 +92,10 @@ class Response:
|
||||
dir_prune_empty: If present, all empty dirs under this one should be
|
||||
removed.
|
||||
open_url: If present, url to display to the user.
|
||||
input_prompt: If present, a line of input is read and placed into
|
||||
endcommand args as 'input'. The first value is the prompt printed
|
||||
before reading and the second is whether it should be read as a
|
||||
password (without echoing to the terminal).
|
||||
end_message: If present, a message that should be printed after all other
|
||||
response processing is done.
|
||||
end_message_end: end arg for end_message print() call.
|
||||
@ -110,6 +114,7 @@ class Response:
|
||||
deletes: Optional[List[str]] = None
|
||||
dir_prune_empty: Optional[str] = None
|
||||
open_url: Optional[str] = None
|
||||
input_prompt: Optional[Tuple[str, bool]] = None
|
||||
end_message: Optional[str] = None
|
||||
end_message_end: str = '\n'
|
||||
end_command: Optional[Tuple[str, Dict]] = None
|
||||
@ -263,6 +268,7 @@ class App:
|
||||
't': json.dumps(self._state.login_token),
|
||||
'd': json.dumps(data),
|
||||
'z': get_tz_offset_seconds(),
|
||||
'y': int(sys.stdout.isatty()),
|
||||
},
|
||||
files=files)
|
||||
response_raw_2.raise_for_status() # Except if anything went wrong.
|
||||
@ -383,6 +389,15 @@ class App:
|
||||
import webbrowser
|
||||
webbrowser.open(url)
|
||||
|
||||
def _handle_input_prompt(self, prompt: str, as_password: bool) -> None:
|
||||
if as_password:
|
||||
from getpass import getpass
|
||||
self._end_command_args['input'] = getpass(prompt=prompt)
|
||||
else:
|
||||
if prompt:
|
||||
print(prompt, end='', flush=True)
|
||||
self._end_command_args['input'] = input()
|
||||
|
||||
def run_user_command(self, args: List[str]) -> None:
|
||||
"""Run a single user command to completion."""
|
||||
# pylint: disable=too-many-branches
|
||||
@ -412,6 +427,9 @@ class App:
|
||||
self._handle_dir_prune_empty(response.dir_prune_empty)
|
||||
if response.open_url is not None:
|
||||
self._handle_open_url(response.open_url)
|
||||
if response.input_prompt is not None:
|
||||
self._handle_input_prompt(prompt=response.input_prompt[0],
|
||||
as_password=response.input_prompt[1])
|
||||
if response.end_message is not None:
|
||||
print(response.end_message,
|
||||
end=response.end_message_end,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user