Class: LearnOpen::ArgumentParser
- Inherits:
-
Object
- Object
- LearnOpen::ArgumentParser
- Defined in:
- lib/learn_open/argument_parser.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(args) ⇒ ArgumentParser
constructor
A new instance of ArgumentParser.
- #learn_config_editor ⇒ Object
- #parse ⇒ Object
Constructor Details
#initialize(args) ⇒ ArgumentParser
Returns a new instance of ArgumentParser.
7 8 9 |
# File 'lib/learn_open/argument_parser.rb', line 7 def initialize(args) @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
5 6 7 |
# File 'lib/learn_open/argument_parser.rb', line 5 def args @args end |
Instance Method Details
#execute ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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 ⇒ Object
29 30 31 32 33 |
# File 'lib/learn_open/argument_parser.rb', line 29 def learn_config_editor config_path = File.('~/.learn-config') editor = YAML.load(File.read(config_path))[:editor] editor.split.first end |
#parse ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/learn_open/argument_parser.rb', line 11 def parse = {} rest = OptionParser.new do |opts| opts.on("--next", "open next lab") do |n| [:next] = n end opts.on("--editor=EDITOR", "specify editor") do |e| [:editor] = e end opts.on("--clone-only", "only download files. No shell") do |co| [:clone_only] = co end end.parse(args) [:lesson_name] = rest.first end |