How to use the cmd2.with_argument_list function in cmd2

To help you get started, we’ve selected a few cmd2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-cmd2 / cmd2 / tests / test_cmd2.py View on Github external
    @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
github python-cmd2 / cmd2 / tests / test_argparse.py View on Github external
    @cmd2.with_argument_list
    def do_arglist(self, arglist):
        if isinstance(arglist, list):
            self.stdout.write('True')
        else:
            self.stdout.write('False')
github python-cmd2 / cmd2 / examples / exit_code.py View on Github external
    @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
github python-cmd2 / cmd2 / examples / arg_print.py View on Github external
    @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))
github python-cmd2 / cmd2 / examples / tab_completion.py View on Github external
    @cmd2.with_argument_list
    def do_list_item(self, args):
        """List item command help"""
        self.poutput("You listed {}".format(args))
github python-cmd2 / cmd2 / examples / arg_print.py View on Github external
    @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))
github arthastang / IoT-Implant-Toolkit / toolkit / core / cli / __init__.py View on Github external
    @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():
github python-cmd2 / cmd2 / examples / paged_output.py View on Github external
    @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)
github python-cmd2 / cmd2 / examples / paged_output.py View on Github external
    @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)