aboutsummaryrefslogtreecommitdiff
path: root/lib/lib_ext
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2012-11-28 14:08:39 -0800
committerelijah <elijah@riseup.net>2012-11-28 14:08:39 -0800
commite2c31618b6f70d86c55c348436dd600b2e4ace21 (patch)
tree2bf27e98fc62af402499c0e7736b02b280dfc320 /lib/lib_ext
parent16f9ee1668a06d6b83dfc312d0601d4f235ab8ef (diff)
downloadleap_cli-e2c31618b6f70d86c55c348436dd600b2e4ace21.tar.gz
leap_cli-e2c31618b6f70d86c55c348436dd600b2e4ace21.tar.bz2
command name shuffle -- grouped more commands together as subcommands
Diffstat (limited to 'lib/lib_ext')
-rw-r--r--lib/lib_ext/gli.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/lib_ext/gli.rb b/lib/lib_ext/gli.rb
new file mode 100644
index 0000000..0bfdbc1
--- /dev/null
+++ b/lib/lib_ext/gli.rb
@@ -0,0 +1,56 @@
+#
+# print subcommands indented in the main global help screen
+#
+
+module GLI
+ module Commands
+ module HelpModules
+ class GlobalHelpFormat
+ SUB_CMD_INDENT = " "
+ def format
+ program_desc = @app.program_desc
+ program_long_desc = @app.program_long_desc
+ if program_long_desc
+ wrapper = @wrapper_class.new(Terminal.instance.size[0],4)
+ program_long_desc = "\n #{wrapper.wrap(program_long_desc)}\n\n" if program_long_desc
+ else
+ program_long_desc = "\n"
+ end
+
+ # build a list of commands, sort them so the commands with subcommands are at the bottom
+ commands = @sorter.call(@app.commands_declaration_order.reject(&:nodoc)).sort do |a,b|
+ if a.commands.any? && b.commands.any?; a.name <=> b.name
+ elsif a.commands.any?; 1
+ elsif b.commands.any?; -1
+ else; a.name <=> b.name
+ end
+ end
+
+ # build a list of command info ([name, description]), including subcommands if appropriate
+ command_info_list = []
+ commands.each do |command|
+ name = [command.name, Array(command.aliases)].flatten.join(', ')
+ command_info_list << [name, command.description]
+ if command.commands.any?
+ @sorter.call(command.commands_declaration_order).each do |cmd|
+ if command.get_default_command == cmd.name
+ command_info_list << [SUB_CMD_INDENT + cmd.names,cmd.description + " (default)"]
+ else
+ command_info_list << [SUB_CMD_INDENT + cmd.names,cmd.description]
+ end
+ end
+ end
+ end
+
+ # display
+ command_formatter = ListFormatter.new(command_info_list, @wrapper_class)
+ stringio = StringIO.new
+ command_formatter.output(stringio)
+ commands = stringio.string
+ global_option_descriptions = OptionsFormatter.new(global_flags_and_switches,@wrapper_class).format
+ GLOBAL_HELP.result(binding)
+ end
+ end
+ end
+ end
+end