Class: CukeTagger::Tagger

Inherits:
Object
  • Object
show all
Defined in:
lib/cuketagger/tagger.rb

Constant Summary collapse

USAGE =
"#{File.basename $0} [-v|--version] [-f|--force] [add|remove|replace]:TAG[:REPLACEMENT] [FILE[:LINE]]+"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.execute(args) ⇒ Object



5
6
7
# File 'lib/cuketagger/tagger.rb', line 5

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

Instance Method Details

#execute(args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cuketagger/tagger.rb', line 9

def execute(args)
  abort(USAGE) if args.empty? || args.first =~ /^(-h|--help)$/

  force = false

  args.each do |arg|
    case arg
    when /^-v|--version$/
      puts CukeTagger::Version
    when /^(.+?\.feature)((:\d+)*)$/
     add_feature $1, $2.to_s
    when /^(add|remove):(.+?)$/
      alterations << [$1.to_sym, $2]
    when /^(replace):(.+?):(.+)$/
      alterations << [$1.to_sym, [$2, $3]]
    when /^(-f|--force)$/
      force = true
    else
      abort(USAGE)
    end
  end

  alterations.uniq!

  files = features_to_change.map { |file, line| file }.uniq
  files.each { |file| parse file, force }
end