For option arguments that must be members of an array, do the check in the option parsing by providing an array of allowed option arguments (e.g. vm create -s bad). Emit better errors for options arguments that should be integers (e.g. fw add-rule -s/-e), and for regular arguments that should be integers (e.g. lb create src-port/dst-port). Include help output in additional cases: * invalid id formats with slashes * invalid/duplicate/missing fields used when multiple fields separated by a comma is allowed * invalid object references when using post subcommands * invalid location for list -l option
19 lines
604 B
Ruby
19 lines
604 B
Ruby
# frozen_string_literal: true
|
|
|
|
UbiCli.on("fw").run_on("add-rule") do
|
|
desc "Add a firewall rule"
|
|
|
|
options("ubi fw (location/fw-name | fw-id) add-rule cidr", key: :fw_add_rule) do
|
|
on("-s", "--start-port=port", Integer, "starting (or only) port to allow (default: 0)")
|
|
on("-e", "--end-port=port", Integer, "ending port to allow (default: 65535)")
|
|
end
|
|
|
|
args 1
|
|
|
|
run do |cidr, opts|
|
|
start_port, end_port = opts[:fw_add_rule].values_at(:"start-port", :"end-port")
|
|
id = sdk_object.add_rule(cidr, start_port:, end_port:)[:id]
|
|
response("Added firewall rule with id: #{id}")
|
|
end
|
|
end
|