def cmd(self, _func=_NO_FUNC, name=None, *args, **kwargs):
        if _func is not _NO_FUNC:
            # Support for using this decorator without calling it, e.g.
            #    @app.cmd        <---- note: no parentheses here!
            #    def foo(): pass
            return self.cmd()(_func)

        parser_args = args
        parser_kwargs = kwargs

        def wrapper(func):
            subcommand = name if name is not None else func.__name__

            parser_kwargs.setdefault('help', "")  # improves --help output
            subparser = self._subparsers.add_parser(
                    subcommand, *parser_args, **parser_kwargs)

            # Add global arguments to subcommand as well so that they
            # can be given after the subcommand on the CLI.
            for global_args, global_kwargs in self._global_args:
                subparser.add_argument(*global_args, **global_kwargs)

            # Add any pending arguments
            for args, kwargs in self._pending_args:
                subparser.add_argument(*args, **kwargs)
            self._pending_args = []

            # Add any pending default values
            try:
                pending_defaults = self._defaults.pop(None)
            except KeyError:
                pass  # no pending defaults
            else:
                self._defaults[func] = pending_defaults

            # Store callback function and return the decorated function
            # unmodified
            subparser.set_defaults(_func=func)
            return func

        return wrapper
Decorator to create a command line subcommand for a function.
dataset/ETHPy150Open splunk/splunk-webframework/contrib/aaargh/aaargh.py/App.cmd