From 2d3ed64b5a59d0d3b84d50767965fcb6eb9cba2a Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Fri, 4 Sep 2009 17:08:51 +0200 Subject: [PATCH] Add bash completion for --node node1[:node2] Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Luca Bigliardi <shammash@google.com> --- autotools/build-bash-completion | 43 +++++++++++++++++++++++++++++++++ lib/cli.py | 5 +++- scripts/gnt-backup | 3 ++- scripts/gnt-instance | 3 ++- 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/autotools/build-bash-completion b/autotools/build-bash-completion index 3a986c65a..7edc9df8a 100755 --- a/autotools/build-bash-completion +++ b/autotools/build-bash-completion @@ -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: diff --git a/lib/cli.py b/lib/cli.py index dd98b4d83..7eb05abb4 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -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, ]) diff --git a/scripts/gnt-backup b/scripts/gnt-backup index 2608f87cc..12a667dfb 100755 --- a/scripts/gnt-backup +++ b/scripts/gnt-backup @@ -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"), diff --git a/scripts/gnt-instance b/scripts/gnt-instance index 03a22ce13..498061447 100755 --- a/scripts/gnt-instance +++ b/scripts/gnt-instance @@ -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={}, -- GitLab