def test_commands_config_ok():
    cli_args = ['h']
    parsed = QuickParse(commands_config_ok, cli_args=cli_args)
    assert len(parsed.commands
               ) == 2 and 'h' in parsed.commands and 'help' in parsed.commands
    assert len(parsed.parameters) == 0
    assert len(parsed.non_commands) == 0
    assert parsed.execute() == 'show_help'
    assert parsed.execute('lorem') == 'show_help'
Esempio n. 2
0
def do_stash_list():
    print('Executing \'do_stash_list\'...')


commands_config = {
    '': do_show_help,
    'commit': do_commit,
    'log': do_log,
    'stash': {
        '': do_stash,
        'list': do_stash_list,
    }
}

options_config = [
    ('-m', '--message', str),
    ('-p', '--patch'),
]

parsed = QuickParse(commands_config, options_config)

print('Commands:\n%s' % (pformat(parsed.commands), ))
print('Parameters:\n%s' % (pformat(parsed.parameters), ))
print('Options:\n%s' % (pformat(parsed.options), ))
print('\'-\' numeric argument:\n%s' % (pformat(parsed.numeric), ))
print('\'+\' numeric argument:\n%s' % (pformat(parsed.plusnumeric), ))
print('Functions to call:\n%s' % (pformat(parsed.to_execute), ))

parsed.execute()