Class: Buffet::CLI

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

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLI

Returns a new instance of CLI.



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
41
42
43
# File 'lib/buffet/cli.rb', line 7

def initialize args
  opts = OptionParser.new do |opts|
    opts.banner = "Usage: buffet [options] [spec-files]"

    opts.on('-c', '--config CONFIG',
            'Use the specified CONFIG file') do |config_file|
      Settings.settings_file = File.expand_path(config_file)
    end

    opts.on('-p', '--project PROJECT',
            'Use the specified PROJECT name') do |project_name|
      Settings.project_name = project_name
    end

    opts.on('-x', '--exclude path,...', Array,
            'Exclude the given set of files') do |excludes|
      Settings.excludes = excludes
    end

    opts.on('-l', '--log LOGFILE',
            'Write to log to LOGFILE, instead of default buffet.log') do |log|
      Settings.log_file = log
    end

    opts.on('-v', '--version', 'Show version') do
      puts "#{opts.program_name} #{Buffet::VERSION}"
      exit
    end
  end.parse!(args)

  specs = Buffet.extract_specs_from(opts.empty? ? ['spec'] : opts)

  runner = Runner.new
  runner.run specs

  exit 1 if runner.failed?
end