Class: SuperStamper::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/super_stamper/cli.rb

Class Method Summary collapse

Class Method Details

.execute(stdout, arguments = []) ⇒ Object



5
6
7
8
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
36
37
38
39
40
# File 'lib/super_stamper/cli.rb', line 5

def self.execute(stdout, arguments=[])

  options = {
    :filename     => 'header.txt'
  }
  mandatory_options = %w(  )

  parser = OptionParser.new do |opts|
    opts.banner = <<-BANNER.gsub(/^          /,'')
      Easily add a header recursively to multiple files in your project directory.

      Usage: #{File.basename($0)} [options]

      Options are:
    BANNER
    opts.separator ""
    ########################################################################
    opts.on("-f", "--filename PATH", String,
      "Which file to use as header.",
      "Default: header.txt") { |arg| options[:filename] = arg }
    ########################################################################
    opts.on("-h", "--help",
      "Show this help message.") { stdout.puts opts; exit }
    ########################################################################
    opts.on("-v", "--version", "Print version (#{SuperStamper::VERSION})") { stdout.puts "#{SuperStamper::VERSION}"; exit }
    opts.parse!(arguments)

    if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }
      stdout.puts opts; exit
    end
  end

  filename = options[:filename]
  
  SuperStamper::Base.stamp_recursively( :header_file_name => filename )
end