Updated options with option groups and some other small cleanups.
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from optparse import OptionParser
|
||||
from optparse import OptionParser, OptionGroup
|
||||
from optparse import IndentedHelpFormatter
|
||||
|
||||
from devstack import constants
|
||||
@@ -30,63 +30,62 @@ def parse():
|
||||
help_formatter = IndentedHelpFormatter(width=HELP_WIDTH)
|
||||
parser = OptionParser(version=version_str, formatter=help_formatter)
|
||||
|
||||
#non-boolean options
|
||||
base_group = OptionGroup(parser, "Install/uninstall/start/stop options")
|
||||
known_actions = sorted(constants.ACTIONS)
|
||||
actions = "(" + ", ".join(known_actions) + ")"
|
||||
parser.add_option("-a", "--action",
|
||||
base_group.add_option("-a", "--action",
|
||||
action="store",
|
||||
type="string",
|
||||
dest="action",
|
||||
metavar="ACTION",
|
||||
help="action to perform, ie %s" % (actions))
|
||||
|
||||
parser.add_option("-d", "--directory",
|
||||
base_group.add_option("-d", "--directory",
|
||||
action="store",
|
||||
type="string",
|
||||
dest="dir",
|
||||
metavar="DIR",
|
||||
help="root DIR for new components or "\
|
||||
help="empty root DIR for install or "\
|
||||
"DIR with existing components (ACTION dependent)")
|
||||
|
||||
known_components = sorted(constants.COMPONENT_NAMES)
|
||||
components = "(" + ", ".join(known_components) + ")"
|
||||
parser.add_option("-c", "--component",
|
||||
base_group.add_option("-c", "--component",
|
||||
action="append",
|
||||
dest="component",
|
||||
help="stack component, ie %s" % (components))
|
||||
|
||||
#boolean options
|
||||
parser.add_option("-f", "--force",
|
||||
action="store_true",
|
||||
dest="force",
|
||||
help="force ACTION even if no trace found (ACTION dependent)",
|
||||
default=False)
|
||||
|
||||
parser.add_option("-i", "--ignoredeps",
|
||||
action="store_true",
|
||||
dest="ignore_deps",
|
||||
help="ignore dependencies when performing ACTION")
|
||||
|
||||
parser.add_option("-e", "--ensuredeps",
|
||||
help="openstack component, ie %s" % (components))
|
||||
base_group.add_option("-i", "--ignore-deps",
|
||||
action="store_false",
|
||||
dest="ignore_deps",
|
||||
help="ensure dependencies occur when performing ACTION (the default)",
|
||||
default=False)
|
||||
|
||||
parser.add_option("-s", "--listdeps",
|
||||
dest="ensure_deps",
|
||||
help="ignore dependencies when performing ACTION")
|
||||
base_group.add_option("-e", "--ensure-deps",
|
||||
action="store_true",
|
||||
dest="list_deps",
|
||||
help="show dependencies of COMPONENT",
|
||||
default=False)
|
||||
|
||||
parser.add_option("-r", "--refcomponent",
|
||||
dest="ensure_deps",
|
||||
help="ensure dependencies occur when performing ACTION (default: %default)",
|
||||
default=True)
|
||||
base_group.add_option("-r", "--ref-component",
|
||||
action="append",
|
||||
dest="r_component",
|
||||
metavar="COMPONENT",
|
||||
help="stack component which will not have ACTION applied but will be referenced as if it was (ACTION dependent)")
|
||||
help="component which will not have ACTION applied but will be referenced as if it was (ACTION dependent)")
|
||||
parser.add_option_group(base_group)
|
||||
|
||||
stop_un_group = OptionGroup(parser, "Uninstall/stop options")
|
||||
stop_un_group.add_option("-f", "--force",
|
||||
action="store_true",
|
||||
dest="force",
|
||||
help="force ACTION even if no trace found",
|
||||
default=False)
|
||||
parser.add_option_group(stop_un_group)
|
||||
|
||||
dep_group = OptionGroup(parser, "Dependency options")
|
||||
dep_group.add_option("-s", "--list-deps",
|
||||
action="store_true",
|
||||
dest="list_deps",
|
||||
help="show dependencies of COMPONENT (default: %default)",
|
||||
default=False)
|
||||
parser.add_option_group(dep_group)
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
|
||||
#extract only what we care about
|
||||
output = dict()
|
||||
output['components'] = options.component
|
||||
@@ -95,6 +94,9 @@ def parse():
|
||||
output['action'] = options.action
|
||||
output['list_deps'] = options.list_deps
|
||||
output['force'] = options.force
|
||||
output['ignore_deps'] = options.ignore_deps
|
||||
if(options.ensure_deps):
|
||||
output['ignore_deps'] = False
|
||||
else:
|
||||
output['ignore_deps'] = True
|
||||
output['extras'] = args
|
||||
return output
|
||||
|
Reference in New Issue
Block a user