Sha256: 0ee350124b34e961ea4a992ef721a8f64f5b24520b1d3f2bc3c999f793cef1e8

Contents?: true

Size: 1 KB

Versions: 35

Compression:

Stored size: 1 KB

Contents

module LearnOpen
  class ArgumentParser
    attr_reader :args

    def initialize(args)
      @args = args
    end

    def execute
      config_path = File.expand_path('~/.learn-config')
      editor_data = YAML.load(File.read(config_path))[:editor]
      if editor_data.match(/ /)
        editor_data = editor_data.split(' ').first
      end

      lesson = nil
      next_lesson = false

      configured_editor = !(editor_data.empty? || editor_data.nil?) ? editor_data : nil
      editor_specified = ARGV.detect {|arg| arg.start_with?('--editor=')}.match(/\-\-editor=(.+)/) || configured_editor
      open_after = !!editor_specified

      if !ARGV[0].start_with?('--editor=') && !ARGV[0].start_with?('--next')
        lesson = ARGV[0].sub(/\/$/, '')
      elsif ARGV[0].start_with?('--next')
        next_lesson = true
      end

      if open_after
        editor_specified = editor_specified.is_a?(String) ? editor_specified : editor_specified[1]
      end

      [lesson, editor_specified, next_lesson]
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
learn-open-1.2.22 lib/learn_open/argument_parser.rb
learn-open-1.2.21 lib/learn_open/argument_parser.rb
learn-open-1.2.20 lib/learn_open/argument_parser.rb
learn-open-1.2.19 lib/learn_open/argument_parser.rb
learn-open-1.2.18 lib/learn_open/argument_parser.rb
learn-open-1.2.17 lib/learn_open/argument_parser.rb
learn-open-1.2.16 lib/learn_open/argument_parser.rb
learn-open-1.2.15 lib/learn_open/argument_parser.rb
learn-open-1.2.14 lib/learn_open/argument_parser.rb
learn-open-1.2.13 lib/learn_open/argument_parser.rb
learn-open-1.2.12 lib/learn_open/argument_parser.rb
learn-open-1.2.11 lib/learn_open/argument_parser.rb
learn-open-1.2.10 lib/learn_open/argument_parser.rb
learn-open-1.2.9 lib/learn_open/argument_parser.rb
learn-open-1.2.8 lib/learn_open/argument_parser.rb
learn-open-1.2.7 lib/learn_open/argument_parser.rb
learn-open-1.2.6 lib/learn_open/argument_parser.rb
learn-open-1.2.5 lib/learn_open/argument_parser.rb
learn-open-1.2.3 lib/learn_open/argument_parser.rb
learn-open-1.2.2 lib/learn_open/argument_parser.rb