Sha256: b6e93a63c39c13a0751f466f6ccd7d6a55d886698db47d961174bd9d220d5b36

Contents?: true

Size: 842 Bytes

Versions: 3

Compression:

Stored size: 842 Bytes

Contents

require 'forwardable'

module GitCompound
  module Command
    # Class that parses command arguments
    #
    class Options
      extend Forwardable

      GLOBAL_OPTIONS = [:verbose, :disable_colors]
      delegate [:procedure, :global, :options, :command] => :@parser

      def initialize(argv)
        @parser = Arguments::Parser.new(argv, GLOBAL_OPTIONS)
        set_global_options
      end

      def parse
        [procedure, options]
      end

      def self.verbose=(mode)
        GitCompound::Logger.verbose = mode
      end

      def self.disable_colors=(mode)
        GitCompound::Logger.colors = !mode
      end

      private

      def set_global_options
        self.class.disable_colors = false

        global.each do |option|
          self.class.public_send("#{option}=", true)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
git_compound-0.2.2 lib/git_compound/command/options.rb
git_compound-0.2.1 lib/git_compound/command/options.rb
git_compound-0.2.0 lib/git_compound/command/options.rb