Class: Boxen::CLI

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, flags) ⇒ CLI

Returns a new instance of CLI.



14
15
16
17
18
# File 'lib/boxen/cli.rb', line 14

def initialize(config, flags)
  @config = config
  @flags  = flags
  @puppet = Boxen::Puppeteer.new @config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/boxen/cli.rb', line 10

def config
  @config
end

#flagsObject (readonly)

Returns the value of attribute flags.



11
12
13
# File 'lib/boxen/cli.rb', line 11

def flags
  @flags
end

#puppetObject (readonly)

Returns the value of attribute puppet.



12
13
14
# File 'lib/boxen/cli.rb', line 12

def puppet
  @puppet
end

Class Method Details

.run(*args) ⇒ Object

Run Boxen by wiring together the command-line flags, config, preflights, Puppet execution, and postflights. Returns Puppet’s exit code.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/boxen/cli.rb', line 51

def self.run(*args)
  config = Boxen::Config.load
  flags  = Boxen::Flags.new args

  # Apply command-line flags to the config in case we're changing or
  # overriding anything.

  flags.apply config

  # Run the preflight checks.

  Boxen::Preflight.run config

  # Okay, we're gonna run Puppet. Let's make some dirs.

  Boxen::Util.sudo("mkdir", "-p", config.homedir) &&
    Boxen::Util.sudo("chown", "#{config.user}:staff", config.homedir)

  # Save the config for Puppet (and next time).

  Boxen::Config.save config

  # Make the magic happen.

  status = Boxen::CLI.new(config, flags).run

  # Run the postflight checks.

  Boxen::Postflight.run config if status.zero?

  # Return Puppet's exit status.

  return status
end

Instance Method Details

#runObject



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

def run

  # --env prints out the current BOXEN_ env vars.

  exec "env | grep ^BOXEN_ | sort" if flags.env?

  # --help prints some CLI help and exits.

  abort "#{flags}\n" if flags.help?

  # --projects prints a list of available projects and exits.

  if flags.projects?
    config.projects.each do |project|
      prefix = project.installed? ? "*" : " "
      puts "#{prefix} #{project.name}"
    end

    exit
  end

  # Actually run Puppet and return its exit code. FIX: Here's
  # where we'll reintegrate automatic error reporting.

  return puppet.run
end