diff options
author | elijah <elijah@riseup.net> | 2014-11-24 22:45:27 -0800 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2014-11-24 22:45:27 -0800 |
commit | b839376a507e37a048ea2df53127ed0884310f60 (patch) | |
tree | 68ba30a77c51a3ee1a2c9ddd7187e6743cff08f1 /lib/leap_cli/lib_ext | |
parent | 8450768268c2bdf82cd6d6bfa9972c70bc5cdcac (diff) |
moved core_ext and lib_ext under leap_cli
Diffstat (limited to 'lib/leap_cli/lib_ext')
-rw-r--r-- | lib/leap_cli/lib_ext/capistrano_connections.rb | 16 | ||||
-rw-r--r-- | lib/leap_cli/lib_ext/gli.rb | 52 |
2 files changed, 68 insertions, 0 deletions
diff --git a/lib/leap_cli/lib_ext/capistrano_connections.rb b/lib/leap_cli/lib_ext/capistrano_connections.rb new file mode 100644 index 0000000..c46455f --- /dev/null +++ b/lib/leap_cli/lib_ext/capistrano_connections.rb @@ -0,0 +1,16 @@ +module Capistrano + class Configuration + module Connections + def failed!(server) + @failure_callback.call(server) if @failure_callback + Thread.current[:failed_sessions] << server + end + + def call_on_failure(&block) + @failure_callback = block + end + end + end +end + + diff --git a/lib/leap_cli/lib_ext/gli.rb b/lib/leap_cli/lib_ext/gli.rb new file mode 100644 index 0000000..f9b03be --- /dev/null +++ b/lib/leap_cli/lib_ext/gli.rb @@ -0,0 +1,52 @@ +# +# 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.to_s <=> b.name.to_s + elsif a.commands.any?; 1 + elsif b.commands.any?; -1 + else; a.name.to_s <=> b.name.to_s + 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| + command_info_list << [SUB_CMD_INDENT + command.name.to_s + " " + cmd.names, cmd.description + (command.get_default_command == cmd.name ? " (default)" : "")] + 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, @sorter, @wrapper_class).format + GLOBAL_HELP.result(binding) + end + end + end + end +end |