Files
ubicloud/cli-commands/vm/list.rb
Jeremy Evans af26199496 Add support for vm list CLI command
This supports listing VMs, taking options about what information to
display.

This is the first commit needing to support subcommands, so this adds
the infrastructure for handling CLI commands to UbiRodish.
2025-02-05 11:01:58 -08:00

28 lines
726 B
Ruby

# frozen_string_literal: true
UbiRodish.on("vm", "list") do
options("ubi vm list [options]", key: :vm_list) do
on("-h", "--headers", "show headers")
on("-i", "--id", "show id")
on("-n", "--name", "show name")
on("-l", "--location", "show location")
on("-4", "--ip4", "show IPv4 address")
on("-6", "--ip6", "show IPv6 address")
end
fields = %w[location name id ip4 ip6].freeze.each(&:freeze)
run do |opts|
get(project_path("vm")) do |data|
keys = fields
if (opts = opts[:vm_list])
keys = keys.select { opts[_1.to_sym] }
keys = fields if keys.empty?
headers = opts[:headers]
end
format_rows(keys, data["items"], headers:)
end
end
end