Class: Greenhouse::Commands::Console

Inherits:
Object
  • Object
show all
Includes:
Command
Defined in:
lib/greenhouse/commands/console.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Command

included

Class Method Details

.usageObject



9
10
11
12
13
14
15
16
# File 'lib/greenhouse/commands/console.rb', line 9

def usage
  puts <<USAGE
usage: #{::Greenhouse::CLI.command_name} #{command_name} <application> #{valid_arguments.to_s}

Applications:
#{project_arguments.to_help}
USAGE
end

Instance Method Details

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/greenhouse/commands/console.rb', line 19

def run
  if arguments.empty? || arguments.all? { |arg| valid_arguments.map(&:keys).flatten.include?(arg) }
    puts "An application is required."
    puts
    print "    "
    usage
    return
  end

  app = Projects::applications.select { |application| arguments.map(&:key).include?(application.name) }.first
  if app.nil?
    puts "Application does not exist. Try adding it with `#{::Greenhouse::CLI::binary} add` and initializing it with `#{::Greenhouse::CLI::binary} init`"
    return
  end

  Bundler.with_clean_env do
    app.chdir do
      exec 'bundle exec rails console'
    end
  end
end