Sha256: 7eab576edf45a4372d0f601958dcc61b957050129b83e64f47e930cc213d321a

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

module LessonsIndexer
  class Options < Messenger
    def initialize(argv)
      parse_args(argv).each do |k, v|
        # attr_accessor for each possible option
        self.class.class_eval do
          attr_accessor k
        end

        # setting each option as instance variable
        self.instance_variable_set "@#{k}", v
      end
    end

    private

    def parse_args(argv)
      begin
        Slop.parse argv do |o|
          o.string '-p', '--path', pou('options.path'), default: pou('options.default.path')
          o.bool '-s', '--skip_index', pou('options.skip_index'), default: false
          o.string '-o', '--output', pou('options.output'), default: pou('options.default.output')
          o.bool '-g', '--git', pou('options.git'), default: false
          o.string '-m', '--message', pou('options.message'), default: pou('options.default.message')
          o.bool '-a', '--all', pou('options.all'), default: false
          o.bool '-i', '--headings', pou('options.headings'), default: false
          o.string '-d', '--headings_dir', pou('options.headings_dir'), default: pou('options.default.headings_dir')
          o.bool '-f', '--pdf', pou('options.pdf'), default: false
          o.array '-l', '--lessons', pou('options.lessons'), default: []
          o.on '--help' do
            puts o
            exit
          end
        end.to_hash
      rescue Slop::Error => e
        exit_msg e.message
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lessons_indexer-1.3.0 lib/lessons_indexer/options.rb
lessons_indexer-1.2.2 lib/lessons_indexer/options.rb
lessons_indexer-1.1.0 lib/lessons_indexer/options.rb