Sha256: ba961a44df6a6ed13e56081090b225a3ef1ee04ecbb01d6355a869c599c1ecde

Contents?: true

Size: 917 Bytes

Versions: 8

Compression:

Stored size: 917 Bytes

Contents

# encoding: utf-8

require 'anvil/parser'

module Anvil
  class Task
    # Cli options parsing definition
    module Options
      attr_reader :parser_block

      def help
        parser.help
      end

      def parser(&block)
        @parser_block = block
        @parser ||= build_parser(&block)
      end

      def build_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

8 entries across 8 versions & 1 rubygems

Version Path
anvil-core-0.4.2 lib/anvil/task/options.rb
anvil-core-0.4.1 lib/anvil/task/options.rb
anvil-core-0.4.0 lib/anvil/task/options.rb
anvil-core-0.3.2 lib/anvil/task/options.rb
anvil-core-0.3.1 lib/anvil/task/options.rb
anvil-core-0.3.0 lib/anvil/task/options.rb
anvil-core-0.2.0 lib/anvil/task/options.rb
anvil-core-0.1.0 lib/anvil/task/options.rb