class LearnOpen::ArgumentParser

Attributes

args[R]

Public Class Methods

new(args) click to toggle source
# File lib/learn_open/argument_parser.rb, line 7
def initialize(args)
  @args = args
end

Public Instance Methods

execute() click to toggle source
# File lib/learn_open/argument_parser.rb, line 35
def execute
  cli_args = parse

  editor = cli_args[:editor].empty? ? learn_config_editor : cli_args[:editor]
  cli_args.merge!(editor: editor)

  [
    cli_args[:lesson_name],
    cli_args[:editor],
    cli_args[:next],
    cli_args[:clone_only]
  ]
end
learn_config_editor() click to toggle source
# File lib/learn_open/argument_parser.rb, line 29
def learn_config_editor
  config_path = File.expand_path('~/.learn-config')
  editor = YAML.load(File.read(config_path))[:editor]
  editor.split.first
end
parse() click to toggle source
# File lib/learn_open/argument_parser.rb, line 11
def parse
  options = {}
  rest = OptionParser.new do |opts|
    opts.on("--next", "open next lab") do |n|
      options[:next] = n
    end
    opts.on("--editor=EDITOR", "specify editor") do |e|
      options[:editor] = e
    end

    opts.on("--clone-only", "only download files. No shell") do |co|
      options[:clone_only] = co
    end
  end.parse(args)
  options[:lesson_name] = rest.first
  options
end