From 24cc497c02b97b834d535431ec50d3f75c18ddcd Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Fri, 18 Oct 2019 19:43:25 +0530 Subject: cli: show useful hint in header area of shell in daemonized mode Problem: ------- When auto_use_daemon=true, entering multi-line command-mode/shell-mode appears like the cli is stuck for new users, as we do not display any info now :-) $ targetcli ---- nothing here, is it stuck ? ------- $ targetcli cd /backstores/ get global auto_use_daemon pwd ls exit auto_use_daemon=true /backstores o- backstores ................................................ [...] o- block .................................... [Storage Objects: 0] o- fileio ................................... [Storage Objects: 0] o- pscsi .................................... [Storage Objects: 0] o- ramdisk .................................. [Storage Objects: 0] o- user:glfs ................................ [Storage Objects: 0] Solution: ------- Add some userful info and a '/> ' in each line, $ targetcli targetcli shell version 2.1.50 Entering targetcli batch mode for daemonized approach. Enter multiple commands separated by newline and type 'exit' to run them all in one go. /> cd /backstores/ /> get global auto_use_daemon /> pwd /> ls /> exit auto_use_daemon=true /backstores o- backstores ................................................ [...] o- block .................................... [Storage Objects: 0] o- fileio ................................... [Storage Objects: 0] o- pscsi .................................... [Storage Objects: 0] o- ramdisk .................................. [Storage Objects: 0] o- user:glfs ................................ [Storage Objects: 0] Signed-off-by: Prasanna Kumar Kalever --- scripts/targetcli | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/targetcli b/scripts/targetcli index 9009a14..49355e3 100755 --- a/scripts/targetcli +++ b/scripts/targetcli @@ -163,7 +163,7 @@ def call_daemon(shell, req): sock.close() sys.exit(0) -def get_arguments(): +def get_arguments(shell): readline.set_completer(completer) readline.set_completer_delims('') @@ -180,7 +180,13 @@ def get_arguments(): command = " ".join(sys.argv[argstart:]) 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 @@ -227,7 +233,7 @@ def main(): disable_daemon=True if use_daemon and not disable_daemon: - call_daemon(shell, get_arguments().encode()) + call_daemon(shell, get_arguments(shell).encode()) # does not return try: -- cgit v1.2.1