Commit d8e19f53 authored by Helga Velroyen's avatar Helga Velroyen
Browse files

build-bash-completion: reduce branches



The 'build-bash-completion' script has an enormous
function which triggered a 'too many branches' lint
error and was quite easily splittable in logical
sub-functions.
Signed-off-by: default avatarHelga Velroyen <helgav@google.com>
Reviewed-by: default avatarJose Lopes <jabolopes@google.com>
parent 876fb142
...@@ -50,15 +50,7 @@ from ganeti.tools import burnin ...@@ -50,15 +50,7 @@ from ganeti.tools import burnin
_OPT_NAME_RE = re.compile(r"^-[a-zA-Z0-9]|--[a-z][-a-z0-9]+$") _OPT_NAME_RE = re.compile(r"^-[a-zA-Z0-9]|--[a-z][-a-z0-9]+$")
def WritePreamble(sw, support_debug): def _WriteGntLog(sw, support_debug):
"""Writes the script preamble.
Helper functions should be written here.
"""
sw.Write("# This script is automatically generated at build time.")
sw.Write("# Do not modify manually.")
if support_debug: if support_debug:
sw.Write("_gnt_log() {") sw.Write("_gnt_log() {")
sw.IncIndent() sw.IncIndent()
...@@ -82,6 +74,8 @@ def WritePreamble(sw, support_debug): ...@@ -82,6 +74,8 @@ def WritePreamble(sw, support_debug):
sw.DecIndent() sw.DecIndent()
sw.Write("}") sw.Write("}")
def _WriteNodes(sw):
sw.Write("_ganeti_nodes() {") sw.Write("_ganeti_nodes() {")
sw.IncIndent() sw.IncIndent()
try: try:
...@@ -91,6 +85,8 @@ def WritePreamble(sw, support_debug): ...@@ -91,6 +85,8 @@ def WritePreamble(sw, support_debug):
sw.DecIndent() sw.DecIndent()
sw.Write("}") sw.Write("}")
def _WriteInstances(sw):
sw.Write("_ganeti_instances() {") sw.Write("_ganeti_instances() {")
sw.IncIndent() sw.IncIndent()
try: try:
...@@ -101,6 +97,8 @@ def WritePreamble(sw, support_debug): ...@@ -101,6 +97,8 @@ def WritePreamble(sw, support_debug):
sw.DecIndent() sw.DecIndent()
sw.Write("}") sw.Write("}")
def _WriteJobs(sw):
sw.Write("_ganeti_jobs() {") sw.Write("_ganeti_jobs() {")
sw.IncIndent() sw.IncIndent()
try: try:
...@@ -113,6 +111,8 @@ def WritePreamble(sw, support_debug): ...@@ -113,6 +111,8 @@ def WritePreamble(sw, support_debug):
sw.DecIndent() sw.DecIndent()
sw.Write("}") sw.Write("}")
def _WriteOSAndIAllocator(sw):
for (fnname, paths) in [ for (fnname, paths) in [
("os", pathutils.OS_SEARCH_PATH), ("os", pathutils.OS_SEARCH_PATH),
("iallocator", constants.IALLOCATOR_SEARCH_PATH), ("iallocator", constants.IALLOCATOR_SEARCH_PATH),
...@@ -128,6 +128,8 @@ def WritePreamble(sw, support_debug): ...@@ -128,6 +128,8 @@ def WritePreamble(sw, support_debug):
sw.DecIndent() sw.DecIndent()
sw.Write("}") sw.Write("}")
def _WriteNodegroup(sw):
sw.Write("_ganeti_nodegroup() {") sw.Write("_ganeti_nodegroup() {")
sw.IncIndent() sw.IncIndent()
try: try:
...@@ -137,6 +139,8 @@ def WritePreamble(sw, support_debug): ...@@ -137,6 +139,8 @@ def WritePreamble(sw, support_debug):
sw.DecIndent() sw.DecIndent()
sw.Write("}") sw.Write("}")
def _WriteNetwork(sw):
sw.Write("_ganeti_network() {") sw.Write("_ganeti_network() {")
sw.IncIndent() sw.IncIndent()
try: try:
...@@ -146,6 +150,8 @@ def WritePreamble(sw, support_debug): ...@@ -146,6 +150,8 @@ def WritePreamble(sw, support_debug):
sw.DecIndent() sw.DecIndent()
sw.Write("}") sw.Write("}")
def _WriteFindFirstArg(sw):
# Params: <offset> <options with values> <options without values> # Params: <offset> <options with values> <options without values>
# Result variable: $first_arg_idx # Result variable: $first_arg_idx
sw.Write("_ganeti_find_first_arg() {") sw.Write("_ganeti_find_first_arg() {")
...@@ -175,6 +181,8 @@ def WritePreamble(sw, support_debug): ...@@ -175,6 +181,8 @@ def WritePreamble(sw, support_debug):
sw.DecIndent() sw.DecIndent()
sw.Write("}") sw.Write("}")
def _WriteListOptions(sw):
# Params: <list of options separated by space> # Params: <list of options separated by space>
# Input variable: $first_arg_idx # Input variable: $first_arg_idx
# Result variables: $arg_idx, $choices # Result variables: $arg_idx, $choices
...@@ -205,6 +213,8 @@ def WritePreamble(sw, support_debug): ...@@ -205,6 +213,8 @@ def WritePreamble(sw, support_debug):
sw.DecIndent() sw.DecIndent()
sw.Write("}") sw.Write("}")
def _WriteGntCheckopt(sw, support_debug):
# Params: <long options with equal sign> <all options> # Params: <long options with equal sign> <all options>
# Result variable: $optcur # Result variable: $optcur
sw.Write("_gnt_checkopt() {") sw.Write("_gnt_checkopt() {")
...@@ -234,6 +244,8 @@ def WritePreamble(sw, support_debug): ...@@ -234,6 +244,8 @@ def WritePreamble(sw, support_debug):
sw.DecIndent() sw.DecIndent()
sw.Write("}") sw.Write("}")
def _WriteGntCompgen(sw, support_debug):
# Params: <compgen options> # Params: <compgen options>
# Result variable: $COMPREPLY # Result variable: $COMPREPLY
sw.Write("_gnt_compgen() {") sw.Write("_gnt_compgen() {")
...@@ -247,6 +259,28 @@ def WritePreamble(sw, support_debug): ...@@ -247,6 +259,28 @@ def WritePreamble(sw, support_debug):
sw.Write("}") sw.Write("}")
def WritePreamble(sw, support_debug):
"""Writes the script preamble.
Helper functions should be written here.
"""
sw.Write("# This script is automatically generated at build time.")
sw.Write("# Do not modify manually.")
_WriteGntLog(sw, support_debug)
_WriteNodes(sw)
_WriteInstances(sw)
_WriteJobs(sw)
_WriteOSAndIAllocator(sw)
_WriteNodegroup(sw)
_WriteNetwork(sw)
_WriteFindFirstArg(sw)
_WriteListOptions(sw)
_WriteGntCheckopt(sw, support_debug)
_WriteGntCompgen(sw, support_debug)
def WriteCompReply(sw, args, cur="\"$cur\""): def WriteCompReply(sw, args, cur="\"$cur\""):
sw.Write("_gnt_compgen %s -- %s", args, cur) sw.Write("_gnt_compgen %s -- %s", args, cur)
sw.Write("return") sw.Write("return")
......
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