diff --git a/cli/dcoscli/help/main.py b/cli/dcoscli/help/main.py index 6ebf42a..c9bee9b 100644 --- a/cli/dcoscli/help/main.py +++ b/cli/dcoscli/help/main.py @@ -11,7 +11,7 @@ Options: """ import dcoscli import docopt -from dcos.api import emitting, options, subcommand, util +from dcos.api import cmds, emitting, options, subcommand, util emitter = emitting.FlatEmitter() @@ -26,30 +26,49 @@ def main(): __doc__, version='dcos-help version {}'.format(dcoscli.version)) - if args['help'] and args['--info']: - emitter.publish(__doc__.split('\n')[0]) - # Note: this covers --all also. - # Eventually we will only show commonly used commands for help - # and use --all to show, well, all commands. - elif args['help']: - directory = util.dcos_path() - commands_message = options.make_command_summary_string( - sorted( - subcommand.documentation(command_path) - for command_path - in subcommand.list_paths(directory))) - - emitter.publish( - "Command line utility for the Mesosphere Datacenter Operating " - "System (DCOS). The Mesosphere DCOS is a distributed operating " - "system built around Apache Mesos. This utility provides tools " - "for easy management of a DCOS installation.\n") - emitter.publish("Available DCOS commands in {!r}:".format(directory)) - emitter.publish(commands_message) - emitter.publish( - "\nGet detailed command description with 'dcos --help'.") - - return 0 - else: + returncode, err = cmds.execute(_cmds(), args) + if err is not None: + emitter.publish(err) emitter.publish(options.make_generic_usage_message(__doc__)) return 1 + + return returncode + + +def _cmds(): + """ + :returns: All of the supported commands + :rtype: list of dcos.api.cmds.Command + """ + + return [ + cmds.Command( + hierarchy=['help'], + arg_keys=['--info'], + function=_help), + ] + + +def _help(show_info): + if show_info: + emitter.publish(__doc__.split('\n')[0]) + return 0 + + directory = util.dcos_path() + commands_message = options.make_command_summary_string( + sorted( + subcommand.documentation(command_path) + for command_path + in subcommand.list_paths(directory))) + + emitter.publish( + "Command line utility for the Mesosphere Datacenter Operating\n" + "System (DCOS). The Mesosphere DCOS is a distributed operating\n" + "system built around Apache Mesos. This utility provides tools\n" + "for easy management of a DCOS installation.\n") + emitter.publish("Available DCOS commands in {!r}:".format(directory)) + emitter.publish(commands_message) + emitter.publish( + "\nGet detailed command description with 'dcos --help'.") + + return 0 diff --git a/cli/tests/integrations/cli/test_dcos.py b/cli/tests/integrations/cli/test_dcos.py index d559596..4405269 100644 --- a/cli/tests/integrations/cli/test_dcos.py +++ b/cli/tests/integrations/cli/test_dcos.py @@ -10,10 +10,11 @@ def test_default(): returncode, stdout, stderr = exec_command(['dcos']) assert returncode == 0 - assert stdout == """Command line utility for \ -the Mesosphere Datacenter Operating System (DCOS). The Mesosphere DCOS is \ -a distributed operating system built around Apache Mesos. This utility \ -provides tools for easy management of a DCOS installation. + assert stdout == """\ +Command line utility for the Mesosphere Datacenter Operating +System (DCOS). The Mesosphere DCOS is a distributed operating +system built around Apache Mesos. This utility provides tools +for easy management of a DCOS installation. Available DCOS commands in '{}': diff --git a/cli/tests/integrations/cli/test_help.py b/cli/tests/integrations/cli/test_help.py index 12a9ecb..c069b0f 100644 --- a/cli/tests/integrations/cli/test_help.py +++ b/cli/tests/integrations/cli/test_help.py @@ -44,10 +44,11 @@ def test_list(): returncode, stdout, stderr = exec_command(['dcos', 'help']) assert returncode == 0 - assert stdout == """Command line utility for \ -the Mesosphere Datacenter Operating System (DCOS). The Mesosphere DCOS is \ -a distributed operating system built around Apache Mesos. This utility \ -provides tools for easy management of a DCOS installation. + assert stdout == """\ +Command line utility for the Mesosphere Datacenter Operating +System (DCOS). The Mesosphere DCOS is a distributed operating +system built around Apache Mesos. This utility provides tools +for easy management of a DCOS installation. Available DCOS commands in '{}':