Class: Greenhouse::Commands::New

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Command

included

Class Method Details

.usageObject



10
11
12
# File 'lib/greenhouse/commands/new.rb', line 10

def usage
  puts "usage: #{::Greenhouse::CLI::binary} #{command_name} <name> #{valid_arguments.to_s}"
end

Instance Method Details

#runObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/greenhouse/commands/new.rb', line 15

def run
  if arguments.length == 0
    usage
    exit 1
  end

  projects_directory = arguments.first.key
  if File.exists?(projects_directory)
    STDERR.puts "Directory already exists: #{projects_directory}"
    STDERR.puts "You can try running `#{::Greenhouse::CLI::binary} init` from inside the directory."
    exit 1
  end

  begin
    FileUtils.mkdir(projects_directory)
  rescue
    STDERR.puts "Unable to create projects directory: #{projects_directory}"
    exit 1
  end
  
  exec "cd #{projects_directory}; #{::Greenhouse::CLI::binary} init"
end