Sha256: e2aad64c40e59ea01b57091f7f851adeef16fbbad8009fa9418751691794b132

Contents?: true

Size: 800 Bytes

Versions: 3

Compression:

Stored size: 800 Bytes

Contents

require 'anvil/parser'

module Anvil
  class Task
    module Options
      def help
        parser.help
      end

      def parser(&block)
        @parser ||= define_parser(&block)
      end

      def define_parser(&block)
        parser = Anvil::Parser.new
        parser.task = self
        configure_parser(parser, &block)
        parser
      end

      def configure_parser(parser, &block)
        block ||= proc {}

        if description
          parser.separator ''
          parser.separator description
        end

        parser.separator ''
        parser.separator 'Available options: '
        parser.instance_eval(&block)
        parser
      end

      def parse_options!(arguments)
        parser.parse!(arguments)
        arguments << parser.options
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
anvil-core-0.0.1.pre.alpha.3 lib/anvil/task/options.rb
anvil-core-0.0.1.pre.alpha.2 lib/anvil/task/options.rb
anvil-core-0.0.1.alpha.1 lib/anvil/task/options.rb