Class: Nutella::New

Inherits:
Command show all
Defined in:
lib/commands/new.rb

Instance Method Summary collapse

Instance Method Details

#run(args = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/commands/new.rb', line 8

def run(args=nil)
  app_id = args[0]

  # If no other arguments, show help and quit here
  if args.empty?
    console.warn 'You need to specify a name for your new application'
    return
  end

  # Check that a directory (i.e. an app) with the same name doesn't already exist
  # If it does it looks into it to see if there is a nutella.json file and displays
  # the proper error message
  if File.directory? app_id
    if File.exist? "#{app_id}/nutella.json"
      console.warn "An application named #{app_id} already exists"
      return
    else
      console.warn "A directory named #{app_id} already exists"
      return
    end
  end

  # If all seems good, generate the application skeleton
  create_dir_structure app_id

  # Display a nice success message and return
  console.success "Your new nutella application #{app_id} is ready!"
end