Class: Binpkgbot::Cli

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

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Cli

Returns a new instance of Cli.



7
8
9
# File 'lib/binpkgbot/cli.rb', line 7

def initialize(argv)
  @argv = argv.dup
end

Instance Method Details

#configObject



55
56
57
# File 'lib/binpkgbot/cli.rb', line 55

def config
  @config ||= Config.load_yaml(config_path)
end

#config_pathObject



51
52
53
# File 'lib/binpkgbot/cli.rb', line 51

def config_path
  options[:config] || './binpkgbot.yml'
end

#do_runObject



26
27
28
29
30
31
# File 'lib/binpkgbot/cli.rb', line 26

def do_run
  config.tasks.each do |task|
    task.execute
  end
  0
end

#do_versionObject



21
22
23
24
# File 'lib/binpkgbot/cli.rb', line 21

def do_version
  puts "binpkgbot #{Binpkgbot::VERSION}"
  0
end

#optionsObject



33
34
35
36
37
38
39
# File 'lib/binpkgbot/cli.rb', line 33

def options
  @options ||= {
    config: nil,
    mode: :run,
    debug: false,
  }
end

#optparseObject



41
42
43
44
45
46
47
48
49
# File 'lib/binpkgbot/cli.rb', line 41

def optparse
  @optparse ||= OptionParser.new do |opt|
    opt.on('-v', '--version') { options[:mode] = :version }

    opt.on('-c PATH', '--config PATH', 'config file to use (default: ./binpkgbot.yml)') do |file|
      options[:config] = file
    end
  end
end

#runObject



11
12
13
14
15
16
17
18
19
# File 'lib/binpkgbot/cli.rb', line 11

def run
  optparse.parse!(@argv)
  case options[:mode]
  when :version
    do_version
  when :run
    do_run
  end
end