Beispiel #1
0
    def test_help_command_prompts_for_target(self, mocker):
        mock_input = mocker.patch('__builtin__.raw_input')
        real_command = subject.command()

        real_command.run_for('')

        mock_input.assert_called_with(
            'Which command would you like help for? (blank to cancel) ')
Beispiel #2
0
    def test_help_command_handles_nonexistent_command(self, printing, mocker):
        real_command = subject.command()

        real_command.run_for('booga')

        assert self.mock_print.mock_calls == [
            mocker.call("\nNo help available for command 'booga'\n"),
        ]
Beispiel #3
0
    def test_command(self, printing, mocker):
        real_command = subject.command()

        real_command.run_for('shell')

        assert self.mock_print.mock_calls == [
            mocker.call('\n', end=''),
            mocker.call('_unix-only_\n', end=''),
            mocker.call('\n', end=''),
            mocker.call(
                '`shell` is a SelectCommand that will open a shell into the instance(s) specified in a new terminal window (per specified instance)\n',
                end=''),
            mocker.call('\n', end=''),
        ]
Beispiel #4
0
    def test_help_command_handles_last_command_in_file(self, printing, mocker):
        real_command = subject.command()
        last_documented_command = ''
        last_documentation = []
        with open('USAGE.md', 'rt') as usage_fh:
            while True:
                line = usage_fh.readline()
                if line == '':
                    break
                if line.startswith('### '):
                    last_documented_command = line[4:-1]
                    last_documentation = []
                else:
                    last_documentation.append(mocker.call(line, end=''))

        assert last_documented_command != '', 'No commands found in documentation file'

        real_command.run_for(last_documented_command)

        assert self.mock_print.mock_calls == last_documentation
Beispiel #5
0
        "finds all the sent Gossip, prompts for which to display, and displays a graph representing the Gossip sent from"
    ),
    'stop':
    SelectCommand('stop', lambda instance: instance.stop_node(),
                  "reverts and stops MASQNode on"),
    finish.name():
    finish.command(),  # always "all"
    'shell':
    SelectCommand('shell', lambda instance: instance.shell(),
                  "opens shell(s) on node instance in terminal window"),
    kill.name():
    kill.command(),
    nfo.name():
    nfo.command(),
    help.name():
    help.command(),
    daisy.name():
    daisy.command(),
    cluster.name():
    cluster.command(),
    'set':
    SetCommand(),
    'binaries':
    binaries_command.BinariesCommand(),

    # TODO status command (finds out which instances are running (checks all platforms), for running instances, determines if node is running on them, if they are subverted, etc)
    # it should not load this state into INSTANCES automatically (multiple pairs could be using different cloud instances, so this should enable coordination)
    # status could prompt for which ones we want to claim for this run of TNT, and load only those into INSTANCES.

    # TODO help command with more detailed command info
}
Beispiel #6
0
    def test_command_properties(self):
        real_command = subject.command()

        assert real_command.name == 'help'
        assert real_command.info == "shows usage information for specified command"
Beispiel #7
0
def cli_main():
    if not os.path.exists(globals.zconf_home):
        print(
            colorprint(
                "ZConf directory not found. This could be the result of a botched installation/uninstallation - \nplease follow the installation instructions at https://github.com/varun-ramani/zconf to reinstall ZConf.",
                "red"))
        return

    if len(sys.argv) == 1:
        help.overview()

    if len(sys.argv) == 2:
        if sys.argv[1] == "help":
            help.overview()
        elif sys.argv[1] == "update":
            update.update()
        elif sys.argv[1] == "init":
            init.initialize()
        else:
            err_invalid_command(sys.argv[1])

    if len(sys.argv) == 3:
        if sys.argv[1] == "help":
            help.command(sys.argv[2])

        elif sys.argv[1] == "path":
            if sys.argv[2] == "view":
                path.view()
            else:
                err_invalid_command("path " + sys.argv[2])

        elif sys.argv[1] == "alias":
            if sys.argv[2] == "view":
                alias.view()
            else:
                err_invalid_command("alias " + sys.argv[2])
        elif sys.argv[1] == "plugin":
            if sys.argv[2] == "update":
                plugin.update()
            else:
                err_invalid_command("plugin " + sys.argv[2])
        else:
            err_invalid_command(sys.argv[1])

    if len(sys.argv) == 4:
        if sys.argv[1] == "path":
            if sys.argv[2] == "rm":
                path.remove_segment(sys.argv[3])
            elif sys.argv[2] == "enable":
                path.enable_segment(sys.argv[3])
            elif sys.argv[2] == "disable":
                path.disable_segment(sys.argv[3])
            elif sys.argv[2] == "get":
                path.get_segment(sys.argv[3])
            else:
                err_invalid_command("path " + sys.argv[2])

        elif sys.argv[1] == "alias":
            if sys.argv[2] == "rm":
                alias.remove(sys.argv[3])
            elif sys.argv[2] == "enable":
                alias.enable(sys.argv[3])
            elif sys.argv[2] == "disable":
                alias.disable(sys.argv[3])
            elif sys.argv[2] == "get":
                alias.get(sys.argv[3])
            else:
                err_invalid_command("alias " + sys.argv[2])

        elif sys.argv[1] == "plugin":
            if sys.argv[2] == "view":
                if sys.argv[3] == "all":
                    plugin.view_all()
                elif sys.argv[3] == "local":
                    plugin.view_local()
                elif sys.argv[3] == "remote":
                    plugin.view_remote()
                else:
                    err_invalid_command("plugin view " + sys.argv[3])
            elif sys.argv[2] == "add":
                plugin.add(sys.argv[3])
            elif sys.argv[2] == "rm":
                plugin.remove(sys.argv[3])
            elif sys.argv[2] == "enable":
                plugin.enable(sys.argv[3])
            elif sys.argv[2] == "disable":
                plugin.disable(sys.argv[3])
            else:
                err_invalid_command("plugin " + sys.argv[2])

        elif sys.argv[1] == "theme":
            if sys.argv[2] == "view":
                if sys.argv[3] == "all":
                    theme.view_all()
                elif sys.argv[3] == "local":
                    theme.view_local()
                elif sys.argv[3] == "remote":
                    theme.view_remote()
                else:
                    err_invalid_command("theme view " + sys.argv[3])
            elif sys.argv[2] == "set":
                theme.set(sys.argv[3])
            elif sys.argv[2] == "rm":
                theme.remove(sys.argv[3])
            elif sys.argv[2] == "add":
                theme.add(sys.argv[3])
            else:
                err_invalid_command("theme " + sys.argv[2])

        else:
            err_invalid_command(sys.argv[1])

    if len(sys.argv) == 5:
        if sys.argv[1] == "path":
            if sys.argv[2] == "set":
                path.set_segment(sys.argv[3], sys.argv[4])
            else:
                err_invalid_command("path " + sys.argv[1])
        elif sys.argv[1] == "alias":
            if sys.argv[2] == "set":
                alias.set(sys.argv[3], sys.argv[4])
        else:
            err_invalid_command(sys.argv[1])