Class: Xapixctl::Cli

Inherits:
BaseCli
  • Object
show all
Defined in:
lib/xapixctl/cli.rb

Constant Summary collapse

SUPPORTED_CONTEXTS =
['Project', 'Organization'].freeze

Instance Method Summary collapse

Methods inherited from BaseCli

exit_on_failure?, start

Instance Method Details

#api_resourcesObject



162
163
164
165
166
167
168
169
# File 'lib/xapixctl/cli.rb', line 162

def api_resources
  available_types = connection.available_resource_types.sort_by { |desc| desc['type'] }.filter { |desc| SUPPORTED_CONTEXTS.include?(desc['context']) }
  table = [['Type', 'Required Context', '']]
  table += available_types.map do |desc|
    [desc['type'], desc['context'], PhoenixClient.supported_type?(desc['type']) ? '' : '(unsupported, update CLI)']
  end
  print_table table, indent: 1
end

#applyObject



90
91
92
93
94
95
# File 'lib/xapixctl/cli.rb', line 90

def apply
  Util.resources_from_file(options[:file]) do |desc|
    say "applying #{desc['kind']} #{desc.dig('metadata', 'id')}"
    org_or_prj_connection.apply(desc)
  end
end

#delete(resource_type = nil, resource_id = nil) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/xapixctl/cli.rb', line 114

def delete(resource_type = nil, resource_id = nil)
  if resource_type && resource_id
    org_or_prj_connection.delete(resource_type, resource_id)
    say "DELETED #{resource_type} #{resource_id}"
  elsif options[:file]
    Util.resources_from_file(options[:file]) do |desc|
      res_type = desc['kind']
      res_id = desc.dig('metadata', 'id')
      delete(res_type, res_id)
    end
  else
    warn "need TYPE and ID or --file option"
  end
end

#exportObject



63
64
65
66
# File 'lib/xapixctl/cli.rb', line 63

def export
  get('Project', prj_connection.project)
  prj_connection.resource_types_for_export.each { |type| get(type) }
end

#get(resource_type, resource_id = nil) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/xapixctl/cli.rb', line 43

def get(resource_type, resource_id = nil)
  conn = org_or_prj_connection
  resource_ids = resource_id ? [resource_id] : conn.resource_ids(resource_type)
  resource_ids.each do |res_id|
    say conn.resource(resource_type, res_id, format: options[:format].to_sym)
  end
end

#logs(correlation_id) ⇒ Object



154
155
156
157
# File 'lib/xapixctl/cli.rb', line 154

def logs(correlation_id)
  result = prj_connection.logs(correlation_id)
  say result['logs'].to_yaml
end

#publishObject



137
138
139
140
141
142
# File 'lib/xapixctl/cli.rb', line 137

def publish
  prj_connection.publish do |res|
    res.on_success { |result| show_deployment_status(result) }
    res.on_error { |err, result| show_deployment_status(result); exit_with_api_error(err, result) }
  end
end