Python cliff.command.Command() Examples

The following are 14 code examples of cliff.command.Command(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module cliff.command , or try the search function .
Example #1
Source File: complete.py    From cliff with Apache License 2.0 6 votes vote down vote up
def get_parser(self, prog_name):
        parser = super(CompleteCommand, self).get_parser(prog_name)
        parser.add_argument(
            "--name",
            default=None,
            metavar='<command_name>',
            help="Command name to support with command completion"
        )
        parser.add_argument(
            "--shell",
            default='bash',
            metavar='<shell>',
            choices=sorted(self._formatters.names()),
            help="Shell being used. Use none for data only (default: bash)"
        )
        return parser 
Example #2
Source File: generate.py    From auDeep with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self,
                 app,
                 app_args,
                 wrapper: BaseFeatureLearningWrapper,
                 default_batch_size: int = 500):
        """
        Creates and initializes a new GenerateBaseCommand with the specified parameters.
        
        Parameters
        ----------
        app
            Pass through to `Command`
        app_args
            Pass through to `Command`
        wrapper: FeatureLearningWrapper
            The feature learning wrapper used for generating features
        default_batch_size: int
            Default batch size
        """
        super().__init__(app, app_args)

        self._wrapper = wrapper
        self._default_batch_size = default_batch_size 
Example #3
Source File: barbican.py    From python-barbicanclient with Apache License 2.0 6 votes vote down vote up
def __init__(self, **kwargs):
        self.client = None

        # Patch command.Command to add a default auth_required = True
        command.Command.auth_required = True

        # Some commands do not need authentication
        help.HelpCommand.auth_required = False
        complete.CompleteCommand.auth_required = False

        super(Barbican, self).__init__(
            description=__doc__.strip(),
            version=barbicanclient.__version__,
            command_manager=commandmanager.CommandManager(
                'openstack.key_manager.v1'),
            deferred_help=True,
            **kwargs
        ) 
Example #4
Source File: complete.py    From cliff with Apache License 2.0 5 votes vote down vote up
def get_header(self):
        return ('_' + self.escaped_name + """()
{
  local cur prev words
  COMPREPLY=()
  _get_comp_words_by_ref -n : cur prev words

  # Command data:
""") 
Example #5
Source File: test_command_hooks.py    From cliff with Apache License 2.0 5 votes vote down vote up
def make_app(**kwargs):
    cmd_mgr = commandmanager.CommandManager('cliff.tests')

    # Register a command that succeeds
    cmd = mock.MagicMock(spec=command.Command)
    command_inst = mock.MagicMock(spec=command.Command)
    command_inst.run.return_value = 0
    cmd.return_value = command_inst
    cmd_mgr.add_command('mock', cmd)

    # Register a command that fails
    err_command = mock.Mock(name='err_command', spec=command.Command)
    err_command_inst = mock.Mock(spec=command.Command)
    err_command_inst.run = mock.Mock(
        side_effect=RuntimeError('test exception')
    )
    err_command.return_value = err_command_inst
    cmd_mgr.add_command('error', err_command)

    app = application.App('testing command hooks',
                          '1',
                          cmd_mgr,
                          stderr=mock.Mock(),  # suppress warning messages
                          **kwargs
                          )
    return app 
Example #6
Source File: test_app.py    From cliff with Apache License 2.0 5 votes vote down vote up
def make_app(**kwargs):
    cmd_mgr = commandmanager.CommandManager('cliff.tests')

    # Register a command that succeeds
    command = mock.MagicMock(spec=c_cmd.Command)
    command_inst = mock.MagicMock(spec=c_cmd.Command)
    command_inst.run.return_value = 0
    command.return_value = command_inst
    cmd_mgr.add_command('mock', command)

    # Register a command that fails
    err_command = mock.Mock(name='err_command', spec=c_cmd.Command)
    err_command_inst = mock.Mock(spec=c_cmd.Command)
    err_command_inst.run = mock.Mock(
        side_effect=RuntimeError('test exception')
    )
    err_command.return_value = err_command_inst
    cmd_mgr.add_command('error', err_command)

    app = application.App('testing interactive mode',
                          '1',
                          cmd_mgr,
                          stderr=mock.Mock(),  # suppress warning messages
                          **kwargs
                          )
    return app, command 
Example #7
Source File: test_app.py    From cliff with Apache License 2.0 5 votes vote down vote up
def test_option_parser_abbrev_issue(self):
        class MyCommand(c_cmd.Command):
            def get_parser(self, prog_name):
                parser = super(MyCommand, self).get_parser(prog_name)
                parser.add_argument("--end")
                return parser

            def take_action(self, parsed_args):
                assert(parsed_args.end == '123')

        class MyCommandManager(commandmanager.CommandManager):
            def load_commands(self, namespace):
                self.add_command("mycommand", MyCommand)

        class MyApp(application.App):
            def __init__(self):
                super(MyApp, self).__init__(
                    description='testing',
                    version='0.1',
                    command_manager=MyCommandManager(None),
                )

            def build_option_parser(self, description, version):
                parser = super(MyApp, self).build_option_parser(
                    description,
                    version,
                    argparse_kwargs={'allow_abbrev': False})
                parser.add_argument('--endpoint')
                return parser

        app = MyApp()
        # NOTE(jd) --debug is necessary so assert in take_action()
        # raises correctly here
        app.run(['--debug', 'mycommand', '--end', '123']) 
Example #8
Source File: command.py    From eclcli with Apache License 2.0 5 votes vote down vote up
def run(self, parsed_args):
        self.log.debug('run(%s)', parsed_args)
        return super(Command, self).run(parsed_args) 
Example #9
Source File: shell.py    From eclcli with Apache License 2.0 5 votes vote down vote up
def __init__(self):
        # Patch command.Command to add a default auth_required = True
        command.Command.auth_required = True

        # Some commands do not need authentication
        help.HelpCommand.auth_required = False
        complete.CompleteCommand.auth_required = False

        # Slight change to the meaning of --debug
        self.DEFAULT_DEBUG_VALUE = None
        self.DEFAULT_DEBUG_HELP = 'Set debug logging and traceback on errors.'

        super(ECLClient, self).__init__(
            description=__doc__.strip(),
            version=eclcli.__version__,
            command_manager=commandmanager.CommandManager('ecl.cli'),
            deferred_help=True)

        del self.command_manager.commands['complete']
        # del self.command_manager.commands['help']

        self.api_version = {}

        # Until we have command line arguments parsed, dump any stack traces
        self.dump_stack_trace = True

        # Assume TLS host certificate verification is enabled
        self.verify = True

        self.client_manager = None
        self.command_options = None

        self.do_profile = False 
Example #10
Source File: commands.py    From kayobe with Apache License 2.0 5 votes vote down vote up
def get_parser(self, prog_name):
        parser = super(SeedHypervisorHostCommandRun, self).get_parser(
            prog_name)
        group = parser.add_argument_group("Host Command Run")
        group.add_argument("--command", required=True,
                           help="Command to run (required).")
        return parser 
Example #11
Source File: commands.py    From kayobe with Apache License 2.0 5 votes vote down vote up
def get_parser(self, prog_name):
        parser = super(SeedHostCommandRun, self).get_parser(prog_name)
        group = parser.add_argument_group("Host Command Run")
        group.add_argument("--command", required=True,
                           help="Command to run (required).")
        return parser 
Example #12
Source File: commands.py    From kayobe with Apache License 2.0 5 votes vote down vote up
def get_parser(self, prog_name):
        parser = super(OvercloudHostCommandRun, self).get_parser(prog_name)
        group = parser.add_argument_group("Host Command Run")
        group.add_argument("--command", required=True,
                           help="Command to run (required).")
        return parser 
Example #13
Source File: train.py    From auDeep with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self,
                 app,
                 app_args,
                 default_batch_size: int = 64,
                 default_num_epochs: int = 10,
                 default_learning_rate: float = 0.001,
                 default_run_name: Path = Path("./test-run")):
        """
        Create and initialize a new TrainBaseCommand with the specified parameters.
        
        Parameters
        ----------
        app
            Pass through to `Command`
        app_args
            Pass through to `Command`
        default_batch_size: int
            Default batch size
        default_num_epochs: int
            Default number of epochs
        default_learning_rate: float
            Default learning rate
        default_run_name: Path
            Default run name
        """
        super().__init__(app, app_args)

        self.default_batch_size = default_batch_size
        self.default_num_epochs = default_num_epochs
        self.default_learning_rate = default_learning_rate
        self.default_run_name = default_run_name

        self.model_filename = None
        self.record_files = None
        self.feature_shape = None
        self.num_instances = None 
Example #14
Source File: cli.py    From optuna with MIT License 5 votes vote down vote up
def clean_up(self, cmd, result, err):
        # type: (Command, int, Optional[Exception]) -> None

        if isinstance(err, CLIUsageError):
            self.parser.print_help()