Esempio n. 1
0
def test_fuzzy_no_prefix():
    # search by distance, no common prefix with any command
    cmd_mgr = CommandManager('cliff.fuzzy')
    app = App('test', '1.0', cmd_mgr)
    cmd_mgr.add_command('user', utils.TestCommand)
    matches = app.get_fuzzy_matches('uesr')
    assert matches == ['user']
Esempio n. 2
0
def make_app(**kwargs):
    cmd_mgr = CommandManager('cliff.tests')

    # Register a command that succeeds
    command = mock.MagicMock(spec=Command)
    command_inst = mock.MagicMock(spec=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=Command)
    err_command_inst = mock.Mock(spec=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 = App(
        'testing interactive mode',
        '1',
        cmd_mgr,
        stderr=mock.Mock(),  # suppress warning messages
        **kwargs)
    return app, command
Esempio n. 3
0
def test_fuzzy_no_prefix():
    # search by distance, no common prefix with any command
    cmd_mgr = CommandManager('cliff.fuzzy')
    app = App('test', '1.0', cmd_mgr)
    cmd_mgr.add_command('user', utils.TestCommand)
    matches = app.get_fuzzy_matches('uesr')
    assert matches == ['user']
Esempio n. 4
0
def make_app(**kwargs):
    cmd_mgr = CommandManager('cliff.tests')

    # Register a command that succeeds
    command = mock.MagicMock(spec=Command)
    command_inst = mock.MagicMock(spec=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=Command)
    err_command_inst = mock.Mock(spec=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 = App('testing interactive mode',
              '1',
              cmd_mgr,
              stderr=mock.Mock(),  # suppress warning messages
              **kwargs
              )
    return app, command
Esempio n. 5
0
File: cli.py Progetto: soskek/optuna
    def __init__(self):
        # type: () -> None

        command_manager = CommandManager('optuna.command')
        super(_OptunaApp, self).__init__(
            description='', version=optuna.__version__, command_manager=command_manager)
        for name, cls in _COMMANDS.items():
            command_manager.add_command(name, cls)
Esempio n. 6
0
    def __init__(self):
        command = CommandManager('foreman.op')
        super(ForemanOperations, self).__init__(
            description='Foreman Operations Application',
            version='0.1',
            command_manager=command)

        for k, v in commands.iteritems():
            command.add_command(k, v)
Esempio n. 7
0
def test_fuzzy_same_distance():
    # searched string has the same distance to all commands
    cmd_mgr = CommandManager('cliff.fuzzy')
    app = App('test', '1.0', cmd_mgr)
    cmd_mgr.add_command('user', utils.TestCommand)
    for cmd in cmd_mgr.commands.keys():
        assert damerau_levenshtein('node', cmd, COST) == 8
    matches = app.get_fuzzy_matches('node')
    assert matches == ['complete', 'help', 'user']
Esempio n. 8
0
def test_fuzzy_common_prefix():
    # searched string is a prefix of all commands
    cmd_mgr = CommandManager('cliff.fuzzy')
    app = App('test', '1.0', cmd_mgr)
    cmd_mgr.commands = {}
    cmd_mgr.add_command('user list', utils.TestCommand)
    cmd_mgr.add_command('user show', utils.TestCommand)
    matches = app.get_fuzzy_matches('user')
    assert matches == ['user list', 'user show']
Esempio n. 9
0
def test_fuzzy_same_distance():
    # searched string has the same distance to all commands
    cmd_mgr = CommandManager('cliff.fuzzy')
    app = App('test', '1.0', cmd_mgr)
    cmd_mgr.add_command('user', utils.TestCommand)
    for cmd in cmd_mgr.commands.keys():
        assert damerau_levenshtein('node', cmd, COST) == 8
    matches = app.get_fuzzy_matches('node')
    assert matches == ['complete', 'help', 'user']
Esempio n. 10
0
def test_fuzzy_common_prefix():
    # searched string is a prefix of all commands
    cmd_mgr = CommandManager('cliff.fuzzy')
    app = App('test', '1.0', cmd_mgr)
    cmd_mgr.commands = {}
    cmd_mgr.add_command('user list', utils.TestCommand)
    cmd_mgr.add_command('user show', utils.TestCommand)
    matches = app.get_fuzzy_matches('user')
    assert matches == ['user list', 'user show']
Esempio n. 11
0
def debug(name, cmd_class, argv=None):
    """Helper for debugging single command without package installation."""
    import sys

    if argv is None:
        argv = sys.argv[1:]

    argv = [name] + argv + ["-v", "-v", "--debug"]
    cmd_mgr = CommandManager(__package__, convert_underscores=True)
    cmd_mgr.add_command(name, cmd_class)

    return run_app(cmd_mgr, argv)
Esempio n. 12
0
 def __init__(self):
     command = CommandManager('libcloudcli.app')
     super(LibcloudCLI, self).__init__(
         description='sample app',
         version='0.1',
         command_manager=command,
     )
     commands = {
         'aws': AWS,
     }
     for k, v in commands.iteritems():
         command.add_command(k, v)
Esempio n. 13
0
def debug(name, cmd_class, argv=None):
    """Helps to debug command."""
    import sys

    if argv is None:
        argv = sys.argv[1:]

    argv = [name] + argv + ["-v", "-v", "--debug"]
    cmd_mgr = CommandManager("test_fuel_mirror", convert_underscores=True)
    cmd_mgr.add_command(name, cmd_class)
    return Application(description="The fuel mirror utility test.",
                       version="0.0.1",
                       command_manager=cmd_mgr).run(argv)
Esempio n. 14
0
 def __init__(self):
     command = CommandManager('cosmicpi')
     super(Cli, self).__init__(
         description='CosmicPi command line interface',
         version='0.0.1',
         command_manager=command,
     )
     commands = {
         'status': Status,
         'usb_toggle': UsbToggle,
         'arduino': Arduino
     }
     for k, v in commands.iteritems():
         command.add_command(k, v)
Esempio n. 15
0
 def __init__(self):
     command = CommandManager('cosmicpi')
     super(Cli, self).__init__(
         description=__doc__,
         version=__version__,
         command_manager=command,
     )
     commands = {
         'status': Status,
         'usb_toggle': UsbToggle,
         'arduino': Arduino
     }
     for k, v in commands.iteritems():
         command.add_command(k, v)
Esempio n. 16
0
    def __init__(self):
        command = CommandManager('PomodoroTimer.app')
        super(PomodoroTimer, self).__init__(
            description = 'sample app',
            version = '0.1',
            command_manager = command,
        )
        commands = {
        'pomodoro': MyCommand,
        'listitems': ListItems
        }

        for k, v in commands.iteritems():
            command.add_command(k, v)
Esempio n. 17
0
def debug(name, cmd_class, argv=None):
    """Helper for debugging single command without package installation."""
    import sys

    if argv is None:
        argv = sys.argv[1:]

    argv = [name] + argv + ["-v", "-v", "--debug"]
    cmd_mgr = CommandManager("test_gitrepo", convert_underscores=True)
    cmd_mgr.add_command(name, cmd_class)
    return Application(
        description="The utility for work with git repositories.",
        version=gitrepo.__version__,
        command_manager=cmd_mgr).run(argv)
Esempio n. 18
0
def debug(name, cmd_class, argv=None):
    """Helps to debug command."""
    import sys

    if argv is None:
        argv = sys.argv[1:]

    argv = [name] + argv + ["-v", "-v", "--debug"]
    cmd_mgr = CommandManager("test_fuel_mirror", convert_underscores=True)
    cmd_mgr.add_command(name, cmd_class)
    return Application(
        description="The fuel mirror utility test.",
        version="0.0.1",
        command_manager=cmd_mgr
    ).run(argv)
Esempio n. 19
0
 def __init__(self):
     command = CommandManager('rgwmanage.shell')
     super(radosgwShell, self).__init__(
         description='Ceph Rados gateway manage',
         version='0.1',
         command_manager=command,
     )
     commands = {
         'user-list': rgwmanage.user.ListUsers,
         'user-show': rgwmanage.user.ShowUser,
         'user-update': rgwmanage.user.UpdateUser,
         'user-update-all': rgwmanage.user.UpdateUserAll,
     }
     for k, v in commands.iteritems():
         command.add_command(k, v)
Esempio n. 20
0
def debug(name, cmd_class, argv=None):
    """Helper for debugging single command without package installation."""
    import sys

    if argv is None:
        argv = sys.argv[1:]

    argv = [name] + argv + ["-v", "-v", "--debug"]
    cmd_mgr = CommandManager("test_packetary", convert_underscores=True)
    cmd_mgr.add_command(name, cmd_class)
    return Application(
        description="The utility manages packages and repositories.",
        version="0.0.1",
        command_manager=cmd_mgr
    ).run(argv)
Esempio n. 21
0
 def __init__(self):
     command = CommandManager('gene.app')
     super(GeneApp, self).__init__(
         description='sample app',
         version='0.1',
         command_manager=command,
     )
     commands = {
         'simple': Simple,
         'file': File,
         'files': Files,
         'sample': MyCommand
     }
     for k, v in commands.iteritems():
         command.add_command(k, v)
Esempio n. 22
0
 def __init__(self):
     command = CommandManager('gene.app')
     super(GeneApp, self).__init__(
         description='sample app',
         version='0.1',
         command_manager=command,
     )
     commands = {
         'simple': Simple,
         'file': File,
         'files': Files,
         'sample': MyCommand
     }
     for k, v in commands.iteritems():
         command.add_command(k, v)
Esempio n. 23
0
def debug(name, cmd_class, argv=None):
    """Helper for debugging single command without package installation."""

    import sys

    if argv is None:
        argv = sys.argv[1:]

    argv = [name] + argv + ["-v", "-v", "--debug"]
    cmd_mgr = CommandManager("test_gerritclient", convert_underscores=True)
    cmd_mgr.add_command(name, cmd_class)
    return GerritClient(
        description="CLI tool for managing Gerrit Code Review.",
        version='0.1.1',
        command_manager=cmd_mgr
    ).run(argv)
Esempio n. 24
0
    def __init__(self):
        command = CommandManager('wcscalendar')

        super(WCSCalendarApp, self).__init__(
              description='WCS Calendar',
              version='0.1',
              command_manager=command,
              deferred_help=True,
        )

        commands = {
            'update': UpdateCalendar,
            'create': CreateNewCalendar
        }

        for k in commands:
            command.add_command(k, commands[k])
Esempio n. 25
0
def make_app(**kwargs):
    cmd_mgr = CommandManager("cliff.tests")

    # Register a command that succeeds
    command = mock.MagicMock(spec=Command)
    command_inst = mock.MagicMock(spec=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=Command)
    err_command_inst = mock.Mock(spec=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 = App("testing interactive mode", "1", cmd_mgr, stderr=mock.Mock(), **kwargs)  # suppress warning messages
    return app, command
Esempio n. 26
0
 def __init__(self):
     command = CommandManager('oflogger.command')
     super(OfloggerApp, self).__init__(
         description='OpenFlow logger',
         version='0.1',
         command_manager=command,
     )
     self.log.info('Start running...')
     commands = {
         'topology': TopologyCommand,
         'bandwidth': BandwidthCommand,
         'nodelocation': NodeLocationCommand,
         'servicelocation': ServiceLocationCommand,
         'servicepath': ServicePathCommand,
         'servicetraffic': ServiceTrafficCommand,
         'command': ServiceCmdCommand,
         'overlay': OverlayCommand,
         'deleteservice': DeleteServiceCommand
     }
     for k, v in commands.iteritems():
         command.add_command(k, v)
Esempio n. 27
0
 def __init__(self):
     command = CommandManager('gene.app')
     super(GeneApp, self).__init__(
         description='sample app',
         version='0.3',
         command_manager=command,
     )
     self.parser.add_argument(
         '-i', '--interprettry',
         default=False,
         action='store_true',
         help='try interpret the read file',
     )
     self.parser.add_argument(
         '-n', '--no-time',
         default=False,
         dest='no_time',
         action='store_true',
         help='no display number/time SRT line',
     )
     self.parser.add_argument(
         '-m', '--max-wide',
         action='store',
         dest='max_wide',
         # const=80,
         default=80,
         help='max wide each line',
     )
     commands = {
         'textparse': ParserText,
         'readfile': ReadFile,
         'files': Files,
         'display': Display
     }
     for k, v in commands.iteritems():
         command.add_command(k, v)
Esempio n. 28
0
 def __init__(self):
     command_manager = CommandManager("diplom.benchmark")
     command_manager.add_command("config show", ShowConfig)
     command_manager.add_command("config list", ListConfigs)
     command_manager.add_command("results collect", CollectResults)
     command_manager.add_command("results collectmeans", CollectResultMeans)
     command_manager.add_command("results plotpr", PlotPrResults)
     command_manager.add_command("results plotap", PlotApResults)
     command_manager.add_command("results showpr", ShowPrResults)
     #command_manager.add_command("codebook show", ShowCodebook)
     super(BenchmarkApp, self).__init__(
             description="Benchmark management application",
             version="0.1",
             command_manager=command_manager,
             interactive_app_factory=InteractiveBenchmarkApp,
             )
Esempio n. 29
0
class Bye(Command):
    """Say bye"""
    def get_parser(self, prog_name):
        parser = super().get_parser(prog_name)
        parser.add_argument('name')
        return parser

    def take_action(self, args):
        print('Bye {}'.format(args.name))


# Here we create a CommandManager and App directly
# To customize the CLI you have to sub-class those!

command_manager = CommandManager('greet')
command_manager.add_command('hello', Hello)
command_manager.add_command('bye', Bye)

app = App(
    description='Twitter command line application',
    version='0.1',
    command_manager=command_manager,
)

# Application needs to be run with command line to parse.
if __name__ == '__main__':
    app = App(
        description='Command line interface for the greet package',
        version='0.1',
        command_manager=command_manager,
    )
def given_complete_command():
    cmd_mgr = CommandManager('cliff.tests')
    app = App('testing', '1', cmd_mgr, stdout=FakeStdout())
    sot = complete.CompleteCommand(app, mock.Mock())
    cmd_mgr.add_command('complete', complete.CompleteCommand)
    return sot, app, cmd_mgr
Esempio n. 31
0
def given_complete_command():
    cmd_mgr = CommandManager('cliff.tests')
    app = App('testing', '1', cmd_mgr, stdout=FakeStdout())
    sot = complete.CompleteCommand(app, mock.Mock())
    cmd_mgr.add_command('complete', complete.CompleteCommand)
    return sot, app, cmd_mgr
Esempio n. 32
0
            print u"%s: %s" % (status.user.screen_name, status.text)


class Retweets(TwitterCommand):
    "Display recent retweets from user's timeline"

    def take_action(self, parsed_args):
        api = self.open_api(parsed_args)
        for status in api.retweets:
            print u"%s: %s" % (status.user.screen_name, status.text)


# Command manager and manual registration of sub-commands.
# Ordinarily registration would occur via setuptools entrypoints.
COMMAND_MANAGER = CommandManager('cliff.demo')
COMMAND_MANAGER.add_command('timeline', Timeline)
COMMAND_MANAGER.add_command('mentions', Mentions)
COMMAND_MANAGER.add_command('retweets', Retweets)


# Main application class.
class TwitterApp(App):

    def __init__(self):
        super(TwitterApp, self).__init__(
            description='Twitter command line application',
            version='0.1',
            command_manager=COMMAND_MANAGER,
        )