Class: EPC::Command::ListConfigsCommand

Inherits:
ListCommand show all
Defined in:
lib/epc/command/config/list_configs_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, #klass_name, #object_id, #object_type, #options, #target_id, #target_type

Instance Method Summary collapse

Methods inherited from BaseCommand

#check_options, #context_params, #context_params=, #go, include_module, inherited, #initialize, required_options, #say_err

Methods included from PersistentAttributes

#auth_token, #caller_id, #target_url

Constructor Details

This class inherits a constructor from 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
# File 'lib/epc/command/config/list_configs_command.rb', line 4

def execute(args = [])
  sol_or_project_configs = false

  path = File.expand_path(".")

  config_type, config_id = extract_configuration_level(path, [target_type, target_id])

  raise FatalError, "Configuration context could not inferred" if config_type.nil? || config_id.nil?

  request_path = EPC::Config::CONFIGURATIONS_PATH+"/#{config_type}/#{config_id}"

  if ["solution", "project"].include?(config_type.downcase) && @options[:stage].present?
    request_path += "/#{@options[:stage]}"
  elsif ["solution", "project"].include?(config_type.downcase) && @options[:stage].blank?
    sol_or_project_configs = true
  end

  title = "#{config_type}"
  if config_type == "Solution" && EPC::Config.is_solution_dir?(path) && EPC::Config.get_solution_value(path, "id") == config_id
    title += "-#{EPC::Config.get_solution_value(path, "name")}"
  elsif config_type == "Project" && EPC::Config.is_project_dir?(path) && EPC::Config.get_project_value(path, "id") == config_id
    title += "-#{EPC::Config.get_project_value(path, "name")}"
  end
  title += "(#{config_id})"
  if !@options[:stage].nil? && config_type != "DeploymentStage"
    title += "/#{@options[:stage]}"
  end
  get_configs_from(request_path, title)

  if sol_or_project_configs
    stages = %w(Development Testing Staging Production)
    stages.each do |stage|
      get_configs_from(request_path + "/#{stage}", "#{title}/#{stage}")
    end
  end
  return @status
end

#get_configs_from(path, title) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/epc/command/config/list_configs_command.rb', line 42

def get_configs_from(path, title)
  status, response, headers = client.get(path)
  @status = status
  if status.failure? 
    say_err("Configuration retrieval failed with [#{response[:message]}]")
    return false
  end

  if response.empty?
    say("No configuration keys have been defined for #{title}.")
    return []
  end

  config_table = EPC::TabularOutputter.new(response, [:name, :value, :value_type, :required])
  say("\n" + title)
  say(config_table.print)
end