def test_make_sure_we_clean_default_args(sample_script, capsys): ## todo: we have more cleanup + tests to do! cli = CliApp() @cli.command def cmd_with_explicit_args(aaa=cli.arg(default='spam'), bbb=cli.arg(type=int, default=100), ccc='example'): print('aaa: {0}'.format(aaa)) print('bbb: {0}'.format(bbb)) print('ccc: {0}'.format(ccc)) cli.run(['cmd_with_explicit_args', '--aaa=AAA']) out, err = capsys.readouterr() assert out == 'aaa: AAA\nbbb: 100\nccc: example\n' cmd_with_explicit_args() out, err = capsys.readouterr() assert out == 'aaa: spam\nbbb: 100\nccc: example\n'
#!/usr/bin/env python from __future__ import print_function from clitools import CliApp cli = CliApp() @cli.command def hello(name='world', bye=False): greet = 'Bye' if bye else 'Hello' print("{0}, {1}".format(greet, name)) if __name__ == '__main__': cli.run()
#!/usr/bin/env python from __future__ import print_function from clitools import CliApp cli = CliApp() @cli.command def hello(name="world", bye=False): greet = "Bye" if bye else "Hello" print("{0}, {1}".format(greet, name)) if __name__ == "__main__": cli.run()