Sha256: 29667a62502d1d9ac119d3df7592c982c6a94fd3178ae7b6c939a80ef5869607

Contents?: true

Size: 1.42 KB

Versions: 8

Compression:

Stored size: 1.42 KB

Contents

require 'erb'

module GLI
  module Commands
    module HelpModules
      class GlobalHelpFormat
        def initialize(app)
          @app = app
        end

        def format
          program_desc = @app.program_desc

          command_formatter = ListFormatter.new(@app.commands.values.sort.reject(&:nodoc).map { |command|
            [[command.name,Array(command.aliases)].flatten.join(', '),command.description]
          })
          stringio = StringIO.new
          command_formatter.output(stringio)
          commands = stringio.string

          global_option_descriptions = OptionsFormatter.new(global_flags_and_switches).format

          GLOBAL_HELP.result(binding)
        end

      private

        GLOBAL_HELP = ERB.new(%q(NAME
    <%= File.basename($0) %> - <%= program_desc %>

SYNOPSIS
    <%= usage_string %>

<% unless @app.version_string.nil? %>
VERSION
    <%= @app.version_string %>

<% end %>
<% unless global_flags_and_switches.empty? %>
GLOBAL OPTIONS
<%= global_option_descriptions %>

<% end %>
COMMANDS
<%= commands %>),nil,'<>')

        def global_flags_and_switches
          @app.flags.merge(@app.switches)
        end

        def usage_string
          "#{File.basename($0)} ".tap do |string|
            string << "[global options] " unless global_flags_and_switches.empty?
            string << "command "
            string << "[command options] [arguments...]"
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
gli-2.1.0 lib/gli/commands/help_modules/global_help_format.rb
gli-2.0.0 lib/gli/commands/help_modules/global_help_format.rb
gli-2.0.0.rc8 lib/gli/commands/help_modules/global_help_format.rb
gli-2.0.0.rc7 lib/gli/commands/help_modules/global_help_format.rb
gli-2.0.0.rc6 lib/gli/commands/help_modules/global_help_format.rb
gli-2.0.0.rc5 lib/gli/commands/help_modules/global_help_format.rb
gli-2.0.0.rc4 lib/gli/commands/help_modules/global_help_format.rb
gli-2.0.0.rc3 lib/gli/commands/help_modules/global_help_format.rb