class Threeman::CLI

Public Instance Methods

start() click to toggle source
# File lib/threeman/cli.rb, line 51
def start
  procfile_name = options[:procfile]
  pwd = options[:root] || Dir.pwd
  procfile = Threeman::Procfile.new(File.expand_path(procfile_name, pwd))
  formation = parse_formation(options[:formation] || 'all=1')
  commands = procfile.commands(pwd, options[:port] || 5000, options[:command_prefix], formation)

  frontend_name = options[:frontend] || auto_frontend
  unless frontend_name
    puts "Couldn't determine a frontend to use.  Please specify one using --frontend."
    print_valid_frontend_names
    exit! 1
  end

  valid_frontend_open_option?(frontend_name) if options[:open_in_new_tab]

  frontend(frontend_name, options).run_commands(commands)
end

Private Instance Methods

auto_frontend() click to toggle source
# File lib/threeman/cli.rb, line 89
def auto_frontend
  if File.exist?('/Applications/iTerm.app/Contents/Info.plist')
    iterm_version = `defaults read /Applications/iTerm.app/Contents/Info.plist CFBundleShortVersionString`
    return :iterm3 if iterm_version >= "2.9"
  end

  if File.exist?('/Applications/Utilities/Terminal.app/Contents/Info.plist')
    return :mac_terminal
  end

  `which tmux`
  if $?.success?
    return :tmux
  end
end
dotfile() click to toggle source
# File lib/threeman/cli.rb, line 117
def dotfile
  @dotfile ||= ['.threeman', '.foreman'].find { |filename| File.file?(filename) }
end
frontend(name, options = {}) click to toggle source
# File lib/threeman/cli.rb, line 78
def frontend(name, options = {})
  frontend_lambda = FRONTENDS[name.to_sym]
  unless frontend_lambda
    puts "No frontend named #{name}!"
    print_valid_frontend_names
    exit! 1
  end

  frontend_lambda.call(options)
end
options() click to toggle source

Cribbed mostly from Foreman

Calls superclass method
# File lib/threeman/cli.rb, line 110
def options
  original_options = super
  return original_options unless dotfile
  defaults = ::YAML::load_file(dotfile) || {}
  Thor::CoreExt::HashWithIndifferentAccess.new(defaults.merge(original_options))
end
parse_formation(formation) click to toggle source
# File lib/threeman/cli.rb, line 121
def parse_formation(formation)
  pairs = formation.to_s.gsub(/\s/, "").split(",")

  pairs.inject(Hash.new(0)) do |ax, pair|
    process, amount = pair.split("=")
    process == "all" ? ax.default = amount.to_i : ax[process] = amount.to_i
    ax
  end
end
print_valid_frontend_names() click to toggle source
valid_frontend_open_option?(frontend_name) click to toggle source
# File lib/threeman/cli.rb, line 71
def valid_frontend_open_option?(frontend_name)
  unless frontend_name == :iterm3
    puts "Opening in a new tab is only supported for iterm3"
    exit! 1
  end
end