diff options
| author | Prasanna Kumar Kalever <prasanna.kalever@redhat.com> | 2020-04-03 13:01:06 +0530 |
|---|---|---|
| committer | Prasanna Kumar Kalever <prasanna.kalever@redhat.com> | 2020-04-06 23:21:30 +0530 |
| commit | b60c74594abf6cf681ff8eaa348059c5348399e9 (patch) | |
| tree | 64362b58ea2e83027fd233acc6b9399cf82ecdb6 /scripts/targetcli | |
| parent | e09fa8c531b4a4d2972df8e96e0baf0bdd953715 (diff) | |
| download | targetcli-b60c74594abf6cf681ff8eaa348059c5348399e9.tar.gz | |
daemonized-mode: add interactive shell support
set interactive mode as default to make it appear similar to cli approach,
$ targetcli
targetcli shell version 2.1.51
Entering targetcli interactive mode for daemonized approach.
Type 'exit' to quit.
/> pwd
/
/> cd /iscsi
/> pwd
/iscsi
/> exit
Here we introduce a new global option daemon_use_batch_mode for switching between
batch and interactive modes.
$ targetcli set global daemon_use_batch_mode=true
Parameter daemon_use_batch_mode is now 'true'.
$ targetcli
targetcli shell version 2.1.51
Entering targetcli batch mode for daemonized approach.
Enter multiple commands separated by newline and type 'exit' to run them
all in one go.
/> pwd
/> cd /iscsi
/> pwd
/
/iscsi
Fixes: #160
Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
Diffstat (limited to 'scripts/targetcli')
| -rwxr-xr-x | scripts/targetcli | 59 |
1 files changed, 39 insertions, 20 deletions
diff --git a/scripts/targetcli b/scripts/targetcli index f11ece4..a0eaf7a 100755 --- a/scripts/targetcli +++ b/scripts/targetcli @@ -64,6 +64,7 @@ class TargetCLI(ConfigShell): 'max_backup_files': '10', 'auto_add_default_portal': True, 'auto_use_daemon': False, + 'daemon_use_batch_mode': False, } def usage(): @@ -160,9 +161,8 @@ def call_daemon(shell, req): sock.send(b'-END@OF@DATA-') sock.close() - sys.exit(0) -def get_arguments(shell): +def switch_to_daemon(shell, interactive): readline.set_completer(completer) readline.set_completer_delims('') @@ -173,27 +173,42 @@ def get_arguments(shell): if len(sys.argv) > 1: command = " ".join(sys.argv[1:]) + call_daemon(shell, command.encode()) + sys.exit(0) + + if interactive: + shell.con.display("targetcli shell version %s\n" + "Entering targetcli interactive mode for daemonized approach.\n" + "Type 'exit' to quit.\n" + % targetcli_version) else: - inputs = [] shell.con.display("targetcli shell version %s\n" - "Entering targetcli batch mode for daemonized approach.\n" - "Enter multiple commands separated by newline and " - "type 'exit' to run them all in one go.\n" - % targetcli_version) - while True: - shell.con.raw_write("/> ") - command = six.moves.input() - if command.lower() == "exit": - break + "Entering targetcli batch mode for daemonized approach.\n" + "Enter multiple commands separated by newline and " + "type 'exit' to run them all in one go.\n" + % targetcli_version) + + inputs = [] + real_exit=False + while True: + shell.con.raw_write("/> ") + command = six.moves.input() + if command.lower() == "exit": + real_exit=True + elif not command: + continue + if not interactive: inputs.append(command) - command = '%'.join(inputs) # delimit multiple commands with '%' - - if not command: - sys.exit(1) - - usage_version(command); + if real_exit: + command = '%'.join(inputs) # delimit multiple commands with '%' + call_daemon(shell, command.encode()) + break + else: + if real_exit: + break + call_daemon(shell, command.encode()) - return command + sys.exit(0) def main(): ''' @@ -225,8 +240,12 @@ def main(): if sys.argv[1] in ("disable-daemon", "--disable-daemon"): disable_daemon=True + interactive_mode = True + if shell.prefs['daemon_use_batch_mode']: + interactive_mode = False + if use_daemon and not disable_daemon: - call_daemon(shell, get_arguments(shell).encode()) + switch_to_daemon(shell, interactive_mode) # does not return try: |
