Merge pull request #5376 from bob-smith/galaxyhelp

Display context appropriate help and inform the user they can do '--help <command>'
pull/5471/merge
jctanner 11 years ago
commit 1d9e78f2ab

@ -135,8 +135,10 @@ def build_option_parser(action):
the user wants to execute.
"""
parser = OptionParser()
parser.set_usage("usage: %%prog [%s] [options] ..." % "|".join(VALID_ACTIONS))
usage = "usage: %%prog [%s] [--help] [options] ..." % "|".join(VALID_ACTIONS)
epilog = "\nSee '%s <command> --help' for more information on a specific command.\n\n" % os.path.basename(sys.argv[0])
OptionParser.format_epilog = lambda self, formatter: self.epilog
parser = OptionParser(usage=usage, epilog=epilog)
if not action:
parser.print_help()
@ -246,6 +248,7 @@ def api_lookup_role_by_name(api_server, role_name):
role_name = parts[-1]
print " downloading role '%s', owned by %s" % (role_name, user_name)
except:
parser.print_help()
print "Invalid role name (%s). You must specify username.rolename" % role_name
sys.exit(1)
@ -484,7 +487,7 @@ def install_role(role_name, role_version, role_filename, options):
# Action functions
#-------------------------------------------------------------------------------------
def execute_init(args, options):
def execute_init(args, options, parser):
"""
Executes the init action, which creates the skeleton framework
of a role that complies with the galaxy metadata format.
@ -516,6 +519,7 @@ def execute_init(args, options):
"been modified there already."
sys.exit(1)
except Exception, e:
parser.print_help()
print "No role name specified for init"
sys.exit(1)
@ -577,7 +581,7 @@ def execute_init(args, options):
f.close()
print "%s was created successfully" % role_name
def execute_info(args, options):
def execute_info(args, options, parser):
"""
Executes the info action. This action prints out detailed
information about an installed role as well as info available
@ -586,7 +590,7 @@ def execute_info(args, options):
pass
def execute_install(args, options):
def execute_install(args, options, parser):
"""
Executes the installation action. The args list contains the
roles to be installed, unless -f was specified. The list of roles
@ -601,11 +605,13 @@ def execute_install(args, options):
if len(args) == 0 and not role_file:
# the user needs to specify one of either --role-file
# or specify a single user/role name
parser.print_help()
print "You must specify a user/role name or a roles file"
sys.exit()
elif len(args) == 1 and role_file:
# using a role file is mutually exclusive of specifying
# the role name on the command line
parser.print_help()
print "Please specify a user/role name, or a roles file, but not both"
sys.exit(1)
@ -698,13 +704,14 @@ def execute_install(args, options):
exit_without_ignore(options)
sys.exit(0)
def execute_remove(args, options):
def execute_remove(args, options, parser):
"""
Executes the remove action. The args list contains the list
of roles to be removed. This list can contain more than one role.
"""
if len(args) == 0:
parser.print_help()
print 'You must specify at least one role to remove.'
sys.exit()
@ -718,7 +725,7 @@ def execute_remove(args, options):
print '%s is not installed, skipping.' % role
sys.exit(0)
def execute_list(args, options):
def execute_list(args, options, parser):
"""
Executes the list action. The args list can contain zero
or one role. If one is specified, only that role will be
@ -750,10 +757,12 @@ def execute_list(args, options):
roles_path = get_opt(options, 'roles_path')
roles_path = os.path.expanduser(roles_path)
if not os.path.exists(roles_path):
parser.print_help()
print "The path %s does not exist. Please specify a valid path with --roles-path" % roles_path
sys.exit(1)
elif not os.path.isdir(roles_path):
print "%s exists, but it is not a directory. Please specify a valid path with --roles-path" % roles_path
parser.print_help()
sys.exit(1)
path_files = os.listdir(roles_path)
for path_file in path_files:
@ -780,7 +789,7 @@ def main():
# execute the desired action
if 1: #try:
fn = globals()["execute_%s" % action]
fn(args, options)
fn(args, options, parser)
#except KeyError, e:
# print "Error: %s is not a valid action. Valid actions are: %s" % (action, ", ".join(VALID_ACTIONS))
# sys.exit(1)

Loading…
Cancel
Save