class TapDance::CLI

Attributes

brewfile[RW]
definition[RW]

Public Class Methods

new(*args, &block) click to toggle source
Calls superclass method
# File lib/tap_dance/cli.rb, line 28
def initialize(*args, &block)
  super(*args, &block)

  # Activate shell output
  TapDance.ui = UI::Shell.new(options)
  TapDance.ui.level = "debug" if options["verbose"]

  # Make sure homebrew is installed
  unless command?(:brew)
    TapDance.ui.error "You haven't installed homebrew, or it isn't in your path."
    exit 1
  end

  @definition = nil

  # Activate dry-run mode
  TapDance::BrewCLI.dry_run = options["dry-run"] if options["dry-run"]

  # Find brewfile
  @brewfile = options["brewfile"]
  @brewfile ||= "./Brewfile"
  @brewfile = File.expand_path @brewfile

  TapDance.ui.info "Brewing from #{@brewfile}"

  unless File.exist? @brewfile
    TapDance.ui.error "Nothing to brew! No Brewfile found."
  else
    TapDance.ui.info "Running `brew update` for good measure."
    BrewCLI.update
  end
end

Public Instance Methods

install() click to toggle source
# File lib/tap_dance/cli.rb, line 62
def install
  return unless File.exist? @brewfile
  @definition = TapDance::DSL.evaluate @brewfile
  @definition.execute
end
update(name=nil) click to toggle source
# File lib/tap_dance/cli.rb, line 69
def update(name=nil)
  return unless File.exist? @brewfile
  @definition = TapDance::DSL.evaluate @brewfile
  @definition.execute true
end

Private Instance Methods

command?(name) click to toggle source

Note: susceptible to code injection!

# File lib/tap_dance/cli.rb, line 78
def command?(name)
  system "which #{name.to_s} > /dev/null 2>&1"
end