Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@cmd2.with_argument_list
def do_exit(self, arg_list) -> bool:
"""Exit the application with an optional exit code.
Usage: exit [exit_code]
Where:
* exit_code - integer exit code to return to the shell
"""
# If an argument was provided
if arg_list:
try:
self.exit_code = int(arg_list[0])
except ValueError:
self.perror("{} isn't a valid integer exit code".format(arg_list[0]))
self.exit_code = -1
# Return True to stop the command loop
@cmd2.with_argument_list
def do_arglist(self, arglist):
if isinstance(arglist, list):
self.stdout.write('True')
else:
self.stdout.write('False')
@cmd2.with_argument_list
def do_exit(self, arg_list: List[str]) -> bool:
"""Exit the application with an optional exit code.
Usage: exit [exit_code]
Where:
* exit_code - integer exit code to return to the shell
"""
# If an argument was provided
if arg_list:
try:
self.exit_code = int(arg_list[0])
except ValueError:
self.perror("{} isn't a valid integer exit code".format(arg_list[0]))
self.exit_code = -1
return True
@cmd2.with_argument_list(preserve_quotes=True)
def do_rprint(self, arglist):
"""Print the argument list this basic command is called with (with quotes preserved)."""
self.poutput('rprint was called with the following list of arguments: {!r}'.format(arglist))
@cmd2.with_argument_list
def do_list_item(self, args):
"""List item command help"""
self.poutput("You listed {}".format(args))
@cmd2.with_argument_list
def do_lprint(self, arglist):
"""Print the argument list this basic command is called with."""
self.poutput('lprint was called with the following list of arguments: {!r}'.format(arglist))
@with_argument_list
def do_run(self, arglist):
'''
Run tool selected
'''
argnum = len(arglist)
if argnum == 0 or (argnum == 1 and ('-h' in arglist or '--help' in arglist)):
self.runtool.print_help()
return
toolname, toolarg = self.runtool.parse_known_args(arglist)
plugin_name = toolname.pluginname
print("Run plugin:{} with arguments:{}".format(plugin_name, str(toolarg)))
if plugin_name in self.toollist.keys():
@cmd2.with_argument_list
def do_page_wrap(self, args: List[str]):
"""Read in a text file and display its output in a pager, wrapping long lines if they don't fit.
Usage: page_wrap
"""
if not args:
self.perror('page_wrap requires a path to a file as an argument', traceback_war=False)
return
self.page_file(args[0], chop=False)
@cmd2.with_argument_list
def do_page_truncate(self, args: List[str]):
"""Read in a text file and display its output in a pager, truncating long lines if they don't fit.
Truncated lines can still be accessed by scrolling to the right using the arrow keys.
Usage: page_chop
"""
if not args:
self.perror('page_truncate requires a path to a file as an argument', traceback_war=False)
return
self.page_file(args[0], chop=True)