Class: TuneSpec::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/tune_spec/parser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Parser

Returns a new instance of Parser.



15
16
17
# File 'lib/tune_spec/parser.rb', line 15

def initialize(args)
  @original_args = args
end

Instance Attribute Details

#original_argsObject (readonly)

Returns the value of attribute original_args.



13
14
15
# File 'lib/tune_spec/parser.rb', line 13

def original_args
  @original_args
end

Class Method Details

.parse(args) ⇒ Object



9
10
11
# File 'lib/tune_spec/parser.rb', line 9

def self.parse(args)
  new(args).parse
end

Instance Method Details

#parseObject



19
20
21
# File 'lib/tune_spec/parser.rb', line 19

def parse
  parser.parse!(original_args)
end

#parserObject

rubocop:disable MethodLength



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/tune_spec/parser.rb', line 24

def parser
  OptionParser.new do |parser|
    parser.summary_width = 34

    parser.banner = "Usage: tune [options]\n\n"

    parser.on('--init [PATH]',
              'Create framework folder structure') do |dir|
      base_path = dir || 'lib'
      %w[groups pages steps].each do |folder|
        FileUtils.mkdir_p(base_path)
        path = "#{base_path}/#{folder}"
        exists = directory_exists?(path)
        print_directory(path, exists)
        create_directory(path) unless exists
      end
    end
  end
end