Class: Rebuild::CLI

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

Constant Summary collapse

DEFAULT_OPTIONS =
{
  help:    false,
  update:  false,
  version: false,
}

Class Method Summary collapse

Class Method Details

.startObject



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
# File 'lib/rebuild/cli.rb', line 14

def start
  @installed = CommandLineTools.installed?
  @gitconfig = GitConfig.instance
  options = DEFAULT_OPTIONS.merge(@gitconfig.rebuild_config)

  opt = OptionParser.new
  opt.on('-h', '--help')          { |v| options[:help] = true }
  opt.on('-v', '--version')       { |v| options[:version] = true }
  opt.on('-f', '--force-update')  { |v| options[:update] = true }
  opt.on('-d', '--directory=VAL') { |v| options[:directory] = v }
  opt.on('-s', '--scriptdir=VAL') { |v| options[:scriptdir] = v }
  opt.on('-k', '--keep-sudo')     { |v| options[:keep_sudo] = true }

  args = opt.parse!(ARGV)
  return show_usage    if options[:help]
  return print_version if options[:version]

  keep_sudo if options[:keep_sudo]

  CommandLineTools.install unless CommandLineTools.installed?
  License.agree            unless License.agreed?

  stdin = STDIN.read unless STDIN.isatty
  if args.empty?
    if options[:repo]
      bootstrap(options[:repo], stdin, options)
    elsif @installed
      show_usage
    end
  elsif args.first.include?('/')
    bootstrap(args.first, stdin, options)
  else
    run_command(args.first)
  end
end