コード例 #1
0
    def test_basic_routing(self):
        from clifactory import CommandLineInterface
        cli = CommandLineInterface()

        @cli.endpoint()
        def do_help(args):
            return "Usage: nosetests"

        @cli.endpoint()
        def do_version(args):
            return "1.7.2"

        self.assertEqual("Usage: nosetests", cli.parse(["help"]))
        self.assertEqual("1.7.2", cli.parse(["version"]))
コード例 #2
0
    def test_nested_routing(self):
        from clifactory import CommandLineInterface
        cli = CommandLineInterface()

        @cli.endpoint()
        def do_link_list(args):
            return "eth0"

        @cli.endpoint()
        def do_addr_list(args):
            return "127.0.0.1"

        self.assertEqual("eth0", cli.parse(["link", "list"]))
        self.assertEqual("127.0.0.1", cli.parse(["addr", "list"]))
コード例 #3
0
ファイル: exemple.py プロジェクト: thomas-maurice/clifactory
 
Copyright (C) 2015 Thoms Maurice <*****@*****.**>
 
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
 
           DO WHAT THE F**K YOU WANT TO PUBLIC LICENSE
  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 
 0. You just DO WHAT THE F**K YOU WANT TO.
"""

from clifactory import CommandLineInterface, Argument

cli = CommandLineInterface()
users = ["John Doe", "Dick Head"]


@cli.endpoint(Argument("user", help="username to add"))
def do_user_add(args):
    users.append(args.user)
    print users


@cli.endpoint()
def do_user_list(args):
    print users


cli.parse()