Commit f5ce7613 authored by Iustin Pop's avatar Iustin Pop
Browse files

Ensure a stable content of the bash completion file



Currently, the order of commands in the bash completion file is
random, because the sub-commands are not sorted. This makes it harder
to investigate the differences in packaged Ganeti or in installed
Ganeti, since chunks in this file will have a random order.

To fix this, we sort the subcommands based on the first subcommand in
a given group ('first' also in sorted order); this results in a stable
contents of file, as tested by building it many times and checking for
differences.

The patch also does a few other minor changes to the file
(e.g. updating copyright years, etc.).
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 95e7e676
#!/usr/bin/python
#
# Copyright (C) 2009 Google Inc.
# Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -319,7 +319,7 @@ class CompletionWriter:
wrote_opt = False
for (suggest, allnames) in values.iteritems():
for (suggest, allnames) in values.items():
longnames = [i for i in allnames if i.startswith("--")]
if wrote_opt:
......@@ -551,14 +551,16 @@ def WriteCompletion(sw, scriptname, funcname,
# Group commands by arguments and options
grouped_cmds = {}
for cmd, (_, argdef, optdef, _, _) in commands.iteritems():
for cmd, (_, argdef, optdef, _, _) in commands.items():
if not (argdef or optdef):
continue
grouped_cmds.setdefault((tuple(argdef), tuple(optdef)), set()).add(cmd)
# We're doing options and arguments to commands
sw.Write("""case "${COMP_WORDS[1]}" in""")
for ((argdef, optdef), cmds) in grouped_cmds.items():
sort_grouped = sorted(grouped_cmds.items(),
key=lambda (_, y): sorted(y)[0])
for ((argdef, optdef), cmds) in sort_grouped:
assert argdef or optdef
sw.Write("%s)", "|".join(map(utils.ShellQuote, sorted(cmds))))
sw.IncIndent()
......@@ -610,7 +612,7 @@ def GetCommands(filename, module):
aliases = getattr(module, "aliases", {})
if aliases:
commands = commands.copy()
for name, target in aliases.iteritems():
for name, target in aliases.items():
commands[name] = commands[target]
return commands
......
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