Module: Debra::Cli

Included in:
Debra
Defined in:
lib/debra/cli.rb

Instance Method Summary collapse

Instance Method Details

#execObject



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
44
45
46
47
48
49
50
51
# File 'lib/debra/cli.rb', line 10

def exec

  options = OpenStruct.new

  OptionParser.new do |opts|

    opts.banner = 'Usage: debra [options]'
    opts.on("-h", "--help", "Show this message") {|h| options.help = h}
    opts.on("-r", "--revision revision", "Append a revision to the file, useful if you are doing CI") {|r| options.revision = r}        
    opts.on("-v", "--verbose", "Run verbosely")  {|v| options.verbose = v}
    opts.on("-ffile", "--file file", String, "Load a specific Debfile")  {|f| options.file = f}
    opts.on("--version", "Show version") do
      puts "Debra " + Debra::VERSION.join('.')
      exit
    end

    begin
      opts.parse!
    rescue OptionParser::MissingArgument,
           OptionParser::InvalidOption,
           OptionParser::InvalidArgument => e
      puts e.message + ', use --help for more details'
      exit 1
    end

    if !options.file.nil? && !File.exists?(options.file)
      puts "Cannot find file #{options.file}"
      exit 1
    end

    if options.help
      puts opts
      exit 1
    end   
       
  end
  
  options.file = options.file || find_debfile
  
  run options
              
end

#find_debfileObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/debra/cli.rb', line 53

def find_debfile
  
  DEBFILES.each do |filename|
    file = Dir.pwd + "/#{filename}"
    if File.exists? file
      return file
    end
  end
  
  puts "Cannot find a valid debfile, searched current working directory for #{DEBFILES.join(",")}"
  puts "Please add a valid debfile or use the --file argument"
  exit 1
  
end