9 def callback(cmdline, kvargs):
10 print("match: %s"%(str(kvargs)))
17 def help_callback(cmdline, kvargs):
18 wrapper = textwrap.TextWrapper(initial_indent=" ",
19 subsequent_indent=" ")
20 wrapper2 = textwrap.TextWrapper(initial_indent=" ",
21 subsequent_indent=" ")
22 for c in cmdline.context:
23 # XXX if terminal supports it, use bold and italic
24 print("%s%s%s"%(bold, c.to_expr(), normal))
25 lines = c.get_help().split("\n")
26 print("\n".join(wrapper.wrap(lines[0])))
28 print("\n".join(wrapper2.wrap(l)))
31 def ip_callback_add(cmdline, kvargs):
33 if kvargs["<ip>"] in ip_list:
34 print("already in list")
36 ip_list.append(kvargs["<ip>"])
38 def ip_callback_del(cmdline, kvargs):
40 ip_list.remove(kvargs["<saved-ip>"])
42 def ip_callback_info(cmdline, kvargs):
44 if "<saved-ip>" in kvargs:
45 print("%s is in list"%kvargs["<saved-ip>"])
47 print("%s is not in list"%kvargs["<ip>"])
51 expr = "toto a|b [coin] [bar]",
53 "toto": TextCliCmd("toto", help_str = "help for toto"),
54 "a": TextCliCmd("a", help_str = "help for a"),
55 "b": TextCliCmd("b", help_str = "help for b"),
56 "coin": TextCliCmd("coin", help_str = "help for coin"),
57 "bar": TextCliCmd("bar", help_str = "help for bar"),
60 help_str = "help for command toto. This is a very very " +
61 "long long help to check that the wrapper is able to " +
62 "wrap the text properly."
66 expr = "titi [pouet] <anytext> <count>",
68 "titi": TextCliCmd("titi", help_str = "help for titi"),
69 "pouet": TextCliCmd("pouet", help_str = "help for pouet"),
70 "<anytext>": AnyTextCliCmd(help_str = "help for anytext"),
71 "<count>": IntCliCmd(help_str = "help for count"),
74 help_str = "help for command titi"
80 "regexp": TextCliCmd("regexp", help_str = "help for regexp"),
81 "<re>": RegexpCliCmd("0x([0-9a-fA-F])", help_str = "an hex number"),
84 help_str = "help for command regexp"
90 "ip": TextCliCmd("ip", help_str = "help for ip"),
91 "add": TextCliCmd("add", help_str = "help for add"),
92 "<ip>": IPv4CliCmd(help_str = "An IPv4 address. The format of " +
93 "an IPv4 address is A.B.C.D, each letter is a number" +
94 "between 0 and 255."),
97 help_str = "help for command ip"
101 expr = "ip del <saved-ip>",
103 "ip": TextCliCmd("ip", help_str = "help for ip"),
104 "del": TextCliCmd("del", help_str = "help for del"),
105 "<saved-ip>": ChoiceCliCmd(ip_list, help_str = "an IP previously " +
108 cb = ip_callback_del,
109 help_str = "help for command ip"
113 expr = "ip info <saved-ip>|<ip>", # XXX talk about prio !
115 "ip": TextCliCmd("ip", help_str = "help for ip"),
116 "info": TextCliCmd("info", help_str = "help for info"),
117 "<saved-ip>": ChoiceCliCmd(ip_list, help_str = "an IP previously " +
119 "<ip>": IPv4CliCmd(help_str = "An IPv4 address"),
121 cb = ip_callback_info,
122 help_str = "help for command ip"
126 expr = "file <file>",
128 "file": TextCliCmd("file", help_str = "Help for file. The file " +
129 "can be either a directory or a regular file."),
130 "<file>": FileCliCmd(help_str = "a file"),
133 help_str = "help for command file"
139 "help": TextCliCmd("help", help_str = "help for help"),
142 help_str = "help for command toto"
146 cmdline = pycol.Cmdline()
147 cmdline.add_context("my_context", ctx)
148 cmdline.set_context("my_context")
149 cmdline.set_prompt("my_context> ")