Revision 63d44c55
b/autotools/build-bash-completion | ||
---|---|---|
273 | 273 |
if not suggest: |
274 | 274 |
suggest = opt.choices |
275 | 275 |
|
276 |
if suggest: |
|
277 |
suggest_text = " ".join(sorted(suggest)) |
|
276 |
if (isinstance(suggest, (int, long)) and |
|
277 |
suggest in cli.OPT_COMPL_ALL): |
|
278 |
key = suggest |
|
279 |
elif suggest: |
|
280 |
key = " ".join(sorted(suggest)) |
|
278 | 281 |
else: |
279 |
suggest_text = ""
|
|
282 |
key = ""
|
|
280 | 283 |
|
281 |
values.setdefault(suggest_text, []).extend(opt.all_names)
|
|
284 |
values.setdefault(key, []).extend(opt.all_names)
|
|
282 | 285 |
|
283 | 286 |
# Don't write any code if there are no option values |
284 | 287 |
if not values: |
... | ... | |
301 | 304 |
utils.ShellQuote("|".join(allnames))) |
302 | 305 |
sw.IncIndent() |
303 | 306 |
try: |
304 |
WriteCompReply(sw, "-W %s" % utils.ShellQuote(suggest), cur=cur) |
|
307 |
if suggest == cli.OPT_COMPL_MANY_NODES: |
|
308 |
# TODO: Implement comma-separated values |
|
309 |
WriteCompReply(sw, "-W ''", cur=cur) |
|
310 |
elif suggest == cli.OPT_COMPL_ONE_NODE: |
|
311 |
WriteCompReply(sw, "-W \"$(_ganeti_nodes)\"", cur=cur) |
|
312 |
elif suggest == cli.OPT_COMPL_ONE_INSTANCE: |
|
313 |
WriteCompReply(sw, "-W \"$(_ganeti_instances)\"", cur=cur) |
|
314 |
elif suggest == cli.OPT_COMPL_ONE_OS: |
|
315 |
WriteCompReply(sw, "-W \"$(_ganeti_os)\"", cur=cur) |
|
316 |
elif suggest == cli.OPT_COMPL_ONE_IALLOCATOR: |
|
317 |
WriteCompReply(sw, "-W \"$(_ganeti_iallocator)\"", cur=cur) |
|
318 |
else: |
|
319 |
WriteCompReply(sw, "-W %s" % utils.ShellQuote(suggest), cur=cur) |
|
305 | 320 |
finally: |
306 | 321 |
sw.DecIndent() |
307 | 322 |
|
b/lib/cli.py | ||
---|---|---|
56 | 56 |
"ArgInstance", "ArgNode", "ArgChoice", "ArgHost", |
57 | 57 |
"ARGS_NONE", "ARGS_ONE_INSTANCE", "ARGS_ONE_NODE", |
58 | 58 |
"ARGS_MANY_INSTANCES", "ARGS_MANY_NODES", |
59 |
"OPT_COMPL_ONE_NODE", "OPT_COMPL_ONE_INSTANCE", |
|
60 |
"OPT_COMPL_MANY_NODES", |
|
61 |
"OPT_COMPL_ONE_OS", "OPT_COMPL_ONE_IALLOCATOR", |
|
59 | 62 |
] |
60 | 63 |
|
61 | 64 |
NO_PREFIX = "no_" |
... | ... | |
330 | 333 |
return _SplitKeyVal(opt, value) |
331 | 334 |
|
332 | 335 |
|
336 |
# completion_suggestion is normally a list. Using numeric values not evaluating |
|
337 |
# to False for dynamic completion. |
|
338 |
(OPT_COMPL_MANY_NODES, |
|
339 |
OPT_COMPL_ONE_NODE, |
|
340 |
OPT_COMPL_ONE_INSTANCE, |
|
341 |
OPT_COMPL_ONE_OS, |
|
342 |
OPT_COMPL_ONE_IALLOCATOR) = range(100, 105) |
|
343 |
|
|
344 |
OPT_COMPL_ALL = frozenset([ |
|
345 |
OPT_COMPL_MANY_NODES, |
|
346 |
OPT_COMPL_ONE_NODE, |
|
347 |
OPT_COMPL_ONE_INSTANCE, |
|
348 |
OPT_COMPL_ONE_OS, |
|
349 |
OPT_COMPL_ONE_IALLOCATOR, |
|
350 |
]) |
|
351 |
|
|
352 |
|
|
333 | 353 |
class CliOption(Option): |
334 | 354 |
"""Custom option class for optparse. |
335 | 355 |
|
Also available in: Unified diff