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



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/super_stamper/cli.rb', line 55

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

  options = {
      :filename => 'header.txt',
      :extension => 'rb',
      :quote => false
  }
  mandatory_options = %w(  )

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

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

      Options are:
    BANNER
    opts.separator ""
    ########################################################################
    opts.on("-e", "--extension PATH", String,
            "Which extension to look for.",
            "Default: rb") { |arg| options[:extension] = arg }
    ########################################################################
    opts.on("-f", "--filename PATH", String,
            "Which file to use as header.",
            "Default: header.txt") { |arg| options[:filename] = arg }
    ########################################################################
    opts.on("-q", "--[no-]quote", "Adds a random quote from the Bash.org QDB. Uses your Internet connection to obtain the quotes from the QDB RSS feed.") do |q|
      options[:quote] = q
    end
    ########################################################################
    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]
  extension = options[:extension]
  quote = options[:quote]

  SuperStamper::Base.stamp_recursively(:header_file_name => filename, :extension => extension, :quote => quote)
end