@@ -67,12 +67,13 @@ class TargetCLI(ConfigShell):
67
67
}
68
68
69
69
def usage ():
70
- print ("Usage: %s [--version|--help|CMD|--disable-daemon]" % sys .argv [0 ], file = err )
70
+ print ("Usage: %s [--version|--help|CMD|--disable-daemon|--interactive ]" % sys .argv [0 ], file = err )
71
71
print (" --version\t \t Print version" , file = err )
72
72
print (" --help\t \t Print this information" , file = err )
73
73
print (" CMD\t \t \t Run targetcli shell command and exit" , file = err )
74
74
print (" <nothing>\t \t Enter configuration shell" , file = err )
75
75
print (" --disable-daemon\t Turn-off the global auto use daemon flag" , file = err )
76
+ print (" -i, --interactive\t Enter interactive shell in daemonized mode" , file = err )
76
77
print ("See man page for more information." , file = err )
77
78
sys .exit (- 1 )
78
79
@@ -159,9 +160,8 @@ def call_daemon(shell, req):
159
160
160
161
sock .send (b'-END@OF@DATA-' )
161
162
sock .close ()
162
- sys .exit (0 )
163
163
164
- def get_arguments (shell ):
164
+ def switch_to_daemon (shell , interactive ):
165
165
readline .set_completer (completer )
166
166
readline .set_completer_delims ('' )
167
167
@@ -170,29 +170,43 @@ def get_arguments(shell):
170
170
else :
171
171
readline .parse_and_bind ("tab: complete" )
172
172
173
- if len (sys .argv ) > 1 :
173
+ if len (sys .argv ) > 1 and not interactive :
174
174
command = " " .join (sys .argv [1 :])
175
+ call_daemon (shell , command .encode ())
176
+ sys .exit (0 )
177
+
178
+ if interactive :
179
+ shell .con .display ("targetcli shell version %s\n "
180
+ "Entering targetcli interactive mode for daemonized approach.\n "
181
+ "Type 'exit' to quit.\n "
182
+ % targetcli_version )
175
183
else :
176
- inputs = []
177
184
shell .con .display ("targetcli shell version %s\n "
178
- "Entering targetcli batch mode for daemonized approach.\n "
179
- "Enter multiple commands separated by newline and "
180
- "type 'exit' to run them all in one go.\n "
181
- % targetcli_version )
182
- while True :
183
- shell .con .raw_write ("/> " )
184
- command = six .moves .input ()
185
- if command .lower () == "exit" :
186
- break
185
+ "Entering targetcli batch mode for daemonized approach.\n "
186
+ "Enter multiple commands separated by newline and "
187
+ "type 'exit' to run them all in one go.\n "
188
+ % targetcli_version )
189
+
190
+ inputs = []
191
+ while True :
192
+ real_exit = False
193
+ shell .con .raw_write ("/> " )
194
+ command = six .moves .input ()
195
+ if command .lower () == "exit" :
196
+ real_exit = True
197
+ if not interactive :
187
198
inputs .append (command )
188
- command = '%' .join (inputs ) # delimit multiple commands with '%'
189
-
190
- if not command :
191
- sys .exit (1 )
192
-
193
- usage_version (command );
199
+ command = '%' .join (inputs ) # delimit multiple commands with '%'
200
+ if real_exit :
201
+ if interactive :
202
+ break
203
+ else :
204
+ call_daemon (shell , command .encode ())
205
+ sys .exit (0 )
206
+ if interactive :
207
+ call_daemon (shell , command .encode ())
194
208
195
- return command
209
+ sys . exit ( 0 )
196
210
197
211
def main ():
198
212
'''
@@ -219,13 +233,16 @@ def main():
219
233
use_daemon = True
220
234
221
235
disable_daemon = False
236
+ interactive_mode = False
222
237
if len (sys .argv ) > 1 :
223
238
usage_version (sys .argv [1 ])
224
239
if sys .argv [1 ] in ("disable-daemon" , "--disable-daemon" ):
225
240
disable_daemon = True
241
+ elif sys .argv [1 ] in ("interactive" , "--interactive" , "-i" ):
242
+ interactive_mode = True
226
243
227
244
if use_daemon and not disable_daemon :
228
- call_daemon (shell , get_arguments ( shell ). encode () )
245
+ switch_to_daemon (shell , interactive_mode )
229
246
# does not return
230
247
231
248
try :
0 commit comments