Sha256: 81aa4218cb26e87371f5c90573429f643968744ff4a62f31604b891d9374e081

Contents?: true

Size: 1.06 KB

Versions: 23

Compression:

Stored size: 1.06 KB

Contents

module Rack::App::CLI::Command::Configurator

  extend self

  def configure(command, name, options_parser)
    attach_definitions(command, options_parser, command.class.__option_definitions__)
    update_banner(command, name, options_parser.banner)
  end

  protected

  def attach_definitions(command, optparse, option_definitions)
    option_definitions.each do |h|
      optparse.on(*h[:args]) do |*args|
        command.instance_exec(*args, &h[:block])
      end
    end
  end

  def update_banner(command, name, banner)

    banner.sub!('[options]', "#{name} [options]")

    # [[:req, :a], [:opt, :b], [:rest, :c], [:keyreq, :d], [:keyrest, :e]]
    (command.method(:action).parameters rescue []).each do |type, keyword|
      case type
        when :req
          banner.concat(" <#{keyword}>")

        when :opt
          banner.concat(" [<#{keyword}>]")

        when :rest, :keyrest
          banner.concat(" [<#{keyword}> <#{keyword}> ...]")

      end
    end

    banner.concat("\n\n")
    banner.concat(command.class.description)
    banner.concat("\n\n")

  end

end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
rack-app-11.0.2 lib/rack/app/cli/command/configurator.rb
rack-app-11.0.1 lib/rack/app/cli/command/configurator.rb
rack-app-11.0.0 lib/rack/app/cli/command/configurator.rb
rack-app-10.0.0 lib/rack/app/cli/command/configurator.rb
rack-app-9.0.0 lib/rack/app/cli/command/configurator.rb
rack-app-8.1.0 lib/rack/app/cli/command/configurator.rb
rack-app-8.0.1 lib/rack/app/cli/command/configurator.rb
rack-app-8.0.0 lib/rack/app/cli/command/configurator.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/rack-app-7.7.0/lib/rack/app/cli/command/configurator.rb
rack-app-7.7.0 lib/rack/app/cli/command/configurator.rb
rack-app-7.6.5 lib/rack/app/cli/command/configurator.rb
rack-app-7.6.4 lib/rack/app/cli/command/configurator.rb
rack-app-7.6.3 lib/rack/app/cli/command/configurator.rb
rack-app-7.6.2 lib/rack/app/cli/command/configurator.rb
rack-app-7.6.1 lib/rack/app/cli/command/configurator.rb
rack-app-7.6.0 lib/rack/app/cli/command/configurator.rb
rack-app-7.5.2 lib/rack/app/cli/command/configurator.rb
rack-app-7.5.1 lib/rack/app/cli/command/configurator.rb
rack-app-7.5.0 lib/rack/app/cli/command/configurator.rb
rack-app-7.4.0 lib/rack/app/cli/command/configurator.rb