Files
ubicloud/cli-commands/pg/post/show.rb
Jeremy Evans 27c84a96b3 Add more fields to pg show cli
This adds fields added to the api since the cli was added:

* maintenance-window-start-at
* read-replica
* parent (shown in location/name format)
* read-replicas (shown in location/name format)

The api includes much more information about the read replicas, but
I'm not sure sure how much of this information is useful. If we want
to expose that information in the cli, we probably need to add an
-r option so you can control which fields get displayed.
2025-08-19 09:36:13 -07:00

58 lines
2.0 KiB
Ruby

# frozen_string_literal: true
UbiCli.on("pg").run_on("show") do
desc "Show details for a PostgreSQL database"
fields = %w[id name state location vm-size target-vm-size storage-size-gib target-storage-size-gib version ha-type flavor connection-string primary earliest-restore-time maintenance-window-start-at read-replica parent tags firewall-rules metric-destinations read-replicas ca-certificates].freeze.each(&:freeze)
options("ubi pg (location/pg-name | pg-id) show [options]", key: :pg_show) do
on("-f", "--fields=fields", "show specific fields (comma separated)")
end
help_option_values("Fields:", fields)
run do |opts, cmd|
data = sdk_object.info
opts = opts[:pg_show]
keys = check_fields(opts[:fields], fields, "pg show -f option", cmd)
body = []
underscore_keys(keys).each do |key|
case key
when :parent
body << "parent: "
if (parent = sdk_object.parent)
body << parent.split("/").values_at(-3, -1).join("/")
end
body << "\n"
when :tags
body << "tags:\n"
sdk_object.tags.sort.each do |k, v|
body << " " << k << ": " << v << "\n"
end
when :firewall_rules
body << "firewall rules:\n"
data[key].each_with_index do |rule, i|
body << " " << (i + 1).to_s << ": " << rule[:id] << " " << rule[:cidr].to_s << "\n"
end
when :metric_destinations
body << "metric destinations:\n"
data[key].each_with_index do |md, i|
body << " " << (i + 1).to_s << ": " << md[:id] << " " << md[:username].to_s << " " << md[:url] << "\n"
end
when :read_replicas
body << "read replicas:\n"
sdk_object.read_replicas.each do |rr|
body << " " << rr[:location] << "/" << rr[:name] << "\n"
end
when :ca_certificates
body << "CA certificates:\n" << data[key].to_s << "\n"
else
body << key.to_s << ": " << data[key].to_s << "\n"
end
end
response(body)
end
end