Ejemplo n.º 1
0
def test_list_deprecated_commands():
    # FIXME(dhellmann): Are commands tied too closely to the app? Or
    # do commands know too much about apps by using them to get to the
    # command manager?
    stdout = StringIO()
    app = App('testing', '1',
              utils.TestCommandManager(utils.TEST_NAMESPACE),
              stdout=stdout)
    app.NAME = 'test'
    try:
        app.run(['--help'])
    except SystemExit:
        pass
    help_output = stdout.getvalue()
    assert 'two words' in help_output
    assert 'three word command' in help_output
    assert 'old cmd' not in help_output
Ejemplo n.º 2
0
def test_list_deprecated_commands():
    # FIXME(dhellmann): Are commands tied too closely to the app? Or
    # do commands know too much about apps by using them to get to the
    # command manager?
    stdout = StringIO()
    app = App('testing',
              '1',
              utils.TestCommandManager(utils.TEST_NAMESPACE),
              stdout=stdout)
    app.NAME = 'test'
    try:
        app.run(['--help'])
    except SystemExit:
        pass
    help_output = stdout.getvalue()
    assert 'two words' in help_output
    assert 'three word command' in help_output
    assert 'old cmd' not in help_output
Ejemplo n.º 3
0
def test_list_matching_commands():
    stdout = StringIO()
    app = App('testing', '1',
              utils.TestCommandManager(utils.TEST_NAMESPACE),
              stdout=stdout)
    app.NAME = 'test'
    try:
        assert app.run(['t']) == 2
    except SystemExit:
        pass
    output = stdout.getvalue()
    assert "test: 't' is not a test command. See 'test --help'." in output
    assert 'Did you mean one of these?' in output
    assert 'three word command\n  two words\n' in output
Ejemplo n.º 4
0
def test_list_matching_commands():
    stdout = StringIO()
    app = App('testing', '1',
              utils.TestCommandManager(utils.TEST_NAMESPACE),
              stdout=stdout)
    app.NAME = 'test'
    try:
        assert app.run(['t']) == 2
    except SystemExit:
        pass
    output = stdout.getvalue()
    assert "test: 't' is not a test command. See 'test --help'." in output
    assert 'Did you mean one of these?' in output
    assert 'three word command\n  two words\n' in output
Ejemplo n.º 5
0
    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,
    )
    sys.exit(app.run(sys.argv[1:]))
Ejemplo n.º 6
0
def main(argv=sys.argv[2:]):
    app = App()
    return app.run(argv)
Ejemplo n.º 7
0
def main(argv=sys.argv[1:]):
    myapp = App()
    return myapp.run(argv)