Class: BoringBuilder::CLI

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, out: $stdout, err: $stderr, builder_class: Builder, environment: ENV) ⇒ CLI

Returns a new instance of CLI.



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

def initialize(argv, out: $stdout, err: $stderr, builder_class: Builder, environment: ENV)
  @argv = argv.dup
  @out = out
  @err = err
  @builder_class = builder_class
  @environment = environment
end

Class Method Details

.start(argv = ARGV) ⇒ Object



9
10
11
# File 'lib/boringbuilder/cli.rb', line 9

def self.start(argv = ARGV, **)
  new(argv, **).start
end

Instance Method Details

#runObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/boringbuilder/cli.rb', line 21

def run
  return root_help if @argv.empty? || %w[help --help -h].include?(@argv.first)
  return version if %w[version --version -v].include?(@argv.first)

  command = @argv.shift
  case command
  when "build" then build
  when "doctor" then doctor
  when "init" then initialize_project
  else raise ConfigurationError, "Unknown command '#{command}'. Use build, doctor, init, or version."
  end
end

#startObject



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

def start
  run
rescue BoringBuilder::Error, OptionParser::ParseError => e
  @err.puts "boringbuilder: #{e.message}"
  1
end