Commit 2d3ed64b authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Add bash completion for --node node1[:node2]


Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarLuca Bigliardi <shammash@google.com>
parent 5b0ca9d4
......@@ -339,6 +339,49 @@ class CompletionWriter:
WriteCompReply(sw, "-W \"$(_ganeti_os)\"", cur=cur)
elif suggest == cli.OPT_COMPL_ONE_IALLOCATOR:
WriteCompReply(sw, "-W \"$(_ganeti_iallocator)\"", cur=cur)
elif suggest == cli.OPT_COMPL_INST_ADD_NODES:
sw.Write("local tmp= node1= pfx= curvalue=\"${optcur#*:}\"")
sw.Write("if [[ \"$optcur\" == *:* ]]; then")
sw.IncIndent()
try:
sw.Write("node1=\"${optcur%%:*}\"")
sw.Write("if [[ \"$COMP_WORDBREAKS\" != *:* ]]; then")
sw.IncIndent()
try:
sw.Write("pfx=\"$node1:\"")
finally:
sw.DecIndent()
sw.Write("fi")
finally:
sw.DecIndent()
sw.Write("fi")
sw.Write("_ganeti_dbglog pfx=\"'$pfx'\" curvalue=\"'$curvalue'\""
" node1=\"'$node1'\"")
sw.Write("for i in $(_ganeti_nodes); do")
sw.IncIndent()
try:
sw.Write("if [[ -z \"$node1\" ]]; then")
sw.IncIndent()
try:
sw.Write("tmp=\"$tmp $i $i:\"")
finally:
sw.DecIndent()
sw.Write("elif [[ \"$i\" != \"$node1\" ]]; then")
sw.IncIndent()
try:
sw.Write("tmp=\"$tmp $i\"")
finally:
sw.DecIndent()
sw.Write("fi")
finally:
sw.DecIndent()
sw.Write("done")
WriteCompReply(sw, "-P \"$pfx\" -W \"$tmp\"", cur="\"$curvalue\"")
else:
WriteCompReply(sw, "-W %s" % utils.ShellQuote(suggest), cur=cur)
finally:
......
......@@ -59,6 +59,7 @@ __all__ = ["DEBUG_OPT", "NOHDR_OPT", "SEP_OPT", "GenericMain",
"OPT_COMPL_ONE_NODE", "OPT_COMPL_ONE_INSTANCE",
"OPT_COMPL_MANY_NODES",
"OPT_COMPL_ONE_OS", "OPT_COMPL_ONE_IALLOCATOR",
"OPT_COMPL_INST_ADD_NODES",
]
NO_PREFIX = "no_"
......@@ -340,7 +341,8 @@ def check_key_val(option, opt, value):
OPT_COMPL_ONE_NODE,
OPT_COMPL_ONE_INSTANCE,
OPT_COMPL_ONE_OS,
OPT_COMPL_ONE_IALLOCATOR) = range(100, 105)
OPT_COMPL_ONE_IALLOCATOR,
OPT_COMPL_INST_ADD_NODES) = range(100, 106)
OPT_COMPL_ALL = frozenset([
OPT_COMPL_MANY_NODES,
......@@ -348,6 +350,7 @@ OPT_COMPL_ALL = frozenset([
OPT_COMPL_ONE_INSTANCE,
OPT_COMPL_ONE_OS,
OPT_COMPL_ONE_IALLOCATOR,
OPT_COMPL_INST_ADD_NODES,
])
......
......@@ -213,7 +213,8 @@ import_opts = [
DEBUG_OPT,
cli_option("-n", "--node", dest="node",
help="Target node and optional secondary node",
metavar="<pnode>[:<snode>]"),
metavar="<pnode>[:<snode>]",
completion_suggest=OPT_COMPL_INST_ADD_NODES),
cli_option("-B", "--backend", dest="beparams",
type="keyval", default={},
help="Backend parameters"),
......
......@@ -1369,7 +1369,8 @@ add_opts = [
DEBUG_OPT,
cli_option("-n", "--node", dest="node",
help="Target node and optional secondary node",
metavar="<pnode>[:<snode>]"),
metavar="<pnode>[:<snode>]",
completion_suggest=OPT_COMPL_INST_ADD_NODES),
os_opt,
cli_option("-B", "--backend", dest="beparams",
type="keyval", default={},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment