Class: RubyYacht::Runner::CreateNewProject

Inherits:
Command
  • Object
show all
Defined in:
lib/ruby_yacht/runner/create_new_project.rb

Overview

This command provides help information about other commands.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

#backtick, #default_project, #docker, #docker_machine, #get_machine_info, #log, #project_named, #projects, short_script_name, #system

Instance Attribute Details

#directoryObject

The directory where we should place the config.



18
19
20
# File 'lib/ruby_yacht/runner/create_new_project.rb', line 18

def directory
  @directory
end

#projectObject

The project that we are creating.



15
16
17
# File 'lib/ruby_yacht/runner/create_new_project.rb', line 15

def project
  @project
end

Class Method Details

.commandObject

The name of the command.



7
# File 'lib/ruby_yacht/runner/create_new_project.rb', line 7

def self.command; 'new'; end

.descriptionObject

The short description of the command.



10
11
12
# File 'lib/ruby_yacht/runner/create_new_project.rb', line 10

def self.description
  'Create a new ruby-yacht project'
end

Instance Method Details

#option_parserObject

This method gets the command-line options for the command.



21
22
23
24
25
# File 'lib/ruby_yacht/runner/create_new_project.rb', line 21

def option_parser
  OptionParser.new do |options|
    options.banner = "Usage: #{Command.short_script_name} new [PROJECT] [DIRECTORY]\n\n#{self.class.description}"
  end
end

#parse_positional_arguments(arguments) ⇒ Object

This method extracts arguments from the command line.

Parameters

  • arguments: Array The command line arguments.


32
33
34
35
# File 'lib/ruby_yacht/runner/create_new_project.rb', line 32

def parse_positional_arguments(arguments)
  self.project = arguments.shift
  self.directory = arguments.shift
end

#runObject

This method runs the logic for the command.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ruby_yacht/runner/create_new_project.rb', line 38

def run
  if project.nil?
    log 'You must provide a project'
    log "Run #{Command.short_script_name} help new for more information"
    return false
  end

  if directory.nil?
    log 'You must provide a directory'
    log "Run #{Command.short_script_name} help new for more information"
    return false
  end

  FileUtils.mkdir_p(directory)
  File.open(File.join(directory, 'run.rb'), 'w') do |file|
    write_config_file(file)
  end
  log "Your project has been created in #{directory}/run.rb."
  log "You can go to #{directory} and run `ruby run.rb build` to create your docker containers."
  log "Your initial app will be created in the #{project} directory."
  true
end