Class: FaaStRuby::Command::Project::Down

Inherits:
ProjectBaseCommand show all
Extended by:
Logger
Defined in:
lib/faastruby/cli/commands/project/down.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ProjectBaseCommand

#read_credentials_file

Methods inherited from BaseCommand

#has_user_logged_in?, #help, #load_credentials, #load_yaml, #say, spin, #spin, #write_file

Constructor Details

#initialize(args) ⇒ Down

Returns a new instance of Down.



10
11
12
13
14
15
16
17
18
# File 'lib/faastruby/cli/commands/project/down.rb', line 10

def initialize(args)
  @args = args
  help
  parse_options
  @options['environment'] ||= 'stage'
  @project_yaml = YAML.load(File.read(PROJECT_YAML_FILE))['project'] rescue FaaStRuby::CLI.error("Could not find file 'project.yml'. Are you running this command from the project's folder?")
  @project_name = @project_yaml['name']
  @project_identifier = "-#{@project_yaml['identifier']}" if @project_yaml['identifier']
end

Class Method Details

.helpObject



29
30
31
# File 'lib/faastruby/cli/commands/project/down.rb', line 29

def self.help
  "down [ARGS]"
end

Instance Method Details

#parse_optionsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/faastruby/cli/commands/project/down.rb', line 40

def parse_options
  @options = {'functions' => []}
  while @args.any?
    option = @args.shift
    case option
    when '-y', '--yes'
      @options['force'] = true
    when '--env', '-e'
      @options['environment'] = @args.shift
    else
      FaaStRuby::CLI.error("Unknown argument: #{option}")
    end
  end
end

#runObject



20
21
22
23
24
25
26
27
# File 'lib/faastruby/cli/commands/project/down.rb', line 20

def run
  workspace = "#{@project_name}-#{@options['environment']}#{@project_identifier}"
  if @options['force']
    exec("faastruby destroy-workspace #{workspace} -y")
  else
    exec("faastruby destroy-workspace #{workspace}")
  end
end

#usageObject



33
34
35
36
37
38
# File 'lib/faastruby/cli/commands/project/down.rb', line 33

def usage
  puts "Usage: faastruby #{self.class.help}"
  puts %(
-e,--env ENVIRONMENT           # ENVIRONMENT is added to the project name to compose the workspace name.
  )
end