Class: EPC::Command::DeleteConfigCommand

Inherits:
BaseCommand show all
Defined in:
lib/epc/command/delete_config_command.rb

Constant Summary

Constants inherited from BaseCommand

BaseCommand::GIVEUP_TICKS, BaseCommand::SLEEP_TIME, BaseCommand::TICKER_TICKS

Instance Attribute Summary

Attributes inherited from BaseCommand

#client, #options

Instance Method Summary collapse

Methods inherited from BaseCommand

#go, inherited, #initialize, #method_missing, required_arguments_count, required_options, #respond_to?

Methods included from PersistentAttributes

#auth_token, #caller_id, #target_url

Constructor Details

This class inherits a constructor from EPC::Command::BaseCommand

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class EPC::Command::BaseCommand

Instance Method Details

#execute(*args) ⇒ Object

Raises:



4
5
6
7
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/epc/command/delete_config_command.rb', line 4

def execute(*args)
  if args.empty?
    say("You must specify the key you wish to delete.")
    return 1
  end

  path = "."
  path = File.expand_path(path)

  config_type, config_id = extract_configuration_level(path, @options)
  request_path = EPC::Config::CONFIGURATIONS_PATH+"/#{config_type}/#{config_id}"

  if ["solution", "project"].include?(config_type.downcase) && !@options[:stage_name].nil?
    request_path += "/#{@options[:stage_name]}"
  end

  status, response, headers = client.get(request_path)

  raise FatalError, "Configuration retrieval failed with [#{response[:message]}]" if status.failure?

  existing_keys = response

  if existing_keys.empty?
    say("There are no configurations defined for this project.")
    return 1
  end

  args.each do |key|
    key_id = existing_keys.detect{|k| k[:name] == key }[:id] rescue nil
    if key_id.nil?
      say("#{key} is not defined.")
      return 1
    end

    question = "Are you sure you want to delete the config value [#{key}] defined on [#{config_type}-#{config_id}"
    if ["solution", "project"].include?(config_type.downcase) && !@options[:stage].nil?
      question += "-#{@options[:stage]}"
    end

    question += "]. Correct? [Yn] "

    proceed = ask_yn(question)
    if proceed.upcase == 'N'
      next
    end

    status, response, headers = client.delete(EPC::Config::CONFIGURATIONS_PATH + "/#{key_id}")
    if status.failure?
      say("Request failed: [#{response[:message]}]")
    else
      say("#{key} succesfully removed.")
    end
    return status
  end


end