cli: handle optional body parameters (#401)

This commit is contained in:
Adam Leventhal 2023-03-30 12:27:25 -07:00 committed by GitHub
parent 4eb8cd6c21
commit e04bb171f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 235 additions and 4 deletions

View File

@ -273,11 +273,52 @@ impl Generator {
.type_space .type_space
.get_type(&prop_type_id) .get_type(&prop_type_id)
.unwrap(); .unwrap();
// TODO this is maybe a kludge--not completely sure
// of the right way to handle option types. On one
// hand, we could want types from this interface to
// never show us Option<T> types--we could let the
// `required` field give us that information. On
// the other hand, there might be Option types that
// are required ... at least in the JSON sense,
// meaning that we need to include `"foo": null`
// rather than omitting the field. Back to the
// first hand: is that last point just a serde
// issue rather than an interface one?
let maybe_inner_type =
if let typify::TypeDetails::Option(
inner_type_id,
) = prop_type.details()
{
let inner_type = self
.type_space
.get_type(&inner_type_id)
.unwrap();
Some(inner_type)
} else {
None
};
let prop_type =
if let Some(inner_type) = maybe_inner_type {
inner_type
} else {
prop_type
};
let prop_type_ident = prop_type.ident(); let prop_type_ident = prop_type.ident();
let good = let good =
prop_type.has_impl(TypeSpaceImpl::FromStr); prop_type.has_impl(TypeSpaceImpl::FromStr);
let prop_name = prop_name.to_kebab_case(); let prop_name = prop_name.to_kebab_case();
// assert!(good || !required);
// println!(
// "{}::{}: {}; good: {}; required: {}",
// body_args.name(),
// prop_name,
// prop_type.name(),
// good,
// required,
// );
good.then(|| { good.then(|| {
let help = let help =

View File

@ -545,6 +545,18 @@ impl Cli {
.value_parser(clap::value_parser!(types::Name)) .value_parser(clap::value_parser!(types::Name))
.help("The organization's unique name."), .help("The organization's unique name."),
) )
.arg(
clap::Arg::new("description")
.long("description")
.required(false)
.value_parser(clap::value_parser!(String)),
)
.arg(
clap::Arg::new("name")
.long("name")
.required(false)
.value_parser(clap::value_parser!(types::Name)),
)
.about("Update an organization\n\nUse `PUT /v1/organizations/{organization}` instead") .about("Update an organization\n\nUse `PUT /v1/organizations/{organization}` instead")
} }
@ -676,6 +688,18 @@ impl Cli {
.value_parser(clap::value_parser!(types::Name)) .value_parser(clap::value_parser!(types::Name))
.help("The project's unique name within the organization."), .help("The project's unique name within the organization."),
) )
.arg(
clap::Arg::new("description")
.long("description")
.required(false)
.value_parser(clap::value_parser!(String)),
)
.arg(
clap::Arg::new("name")
.long("name")
.required(false)
.value_parser(clap::value_parser!(types::Name)),
)
.about("Update a project\n\nUse `PUT /v1/projects/{project}` instead") .about("Update a project\n\nUse `PUT /v1/projects/{project}` instead")
} }
@ -1336,6 +1360,16 @@ impl Cli {
.required(true) .required(true)
.value_parser(clap::value_parser!(String)), .value_parser(clap::value_parser!(String)),
) )
.arg(
clap::Arg::new("ip")
.long("ip")
.required(false)
.value_parser(clap::value_parser!(std::net::IpAddr))
.help(
"The IP address for the interface. One will be auto-assigned if not \
provided.",
),
)
.arg( .arg(
clap::Arg::new("name") clap::Arg::new("name")
.long("name") .long("name")
@ -1414,6 +1448,18 @@ impl Cli {
.required(true) .required(true)
.value_parser(clap::value_parser!(types::Name)), .value_parser(clap::value_parser!(types::Name)),
) )
.arg(
clap::Arg::new("description")
.long("description")
.required(false)
.value_parser(clap::value_parser!(String)),
)
.arg(
clap::Arg::new("name")
.long("name")
.required(false)
.value_parser(clap::value_parser!(types::Name)),
)
.arg( .arg(
clap::Arg::new("primary") clap::Arg::new("primary")
.long("primary") .long("primary")
@ -1838,6 +1884,18 @@ impl Cli {
.required(true) .required(true)
.value_parser(clap::value_parser!(types::Name)), .value_parser(clap::value_parser!(types::Name)),
) )
.arg(
clap::Arg::new("ipv6-prefix")
.long("ipv6-prefix")
.required(false)
.value_parser(clap::value_parser!(types::Ipv6Net))
.help(
"The IPv6 prefix for this VPC.\n\nAll IPv6 subnets created from this VPC \
must be taken from this range, which sould be a Unique Local Address in \
the range `fd00::/48`. The default VPC Subnet will have the first `/64` \
range from this prefix.",
),
)
.arg( .arg(
clap::Arg::new("name") clap::Arg::new("name")
.long("name") .long("name")
@ -1890,6 +1948,24 @@ impl Cli {
.required(true) .required(true)
.value_parser(clap::value_parser!(types::Name)), .value_parser(clap::value_parser!(types::Name)),
) )
.arg(
clap::Arg::new("description")
.long("description")
.required(false)
.value_parser(clap::value_parser!(String)),
)
.arg(
clap::Arg::new("dns-name")
.long("dns-name")
.required(false)
.value_parser(clap::value_parser!(types::Name)),
)
.arg(
clap::Arg::new("name")
.long("name")
.required(false)
.value_parser(clap::value_parser!(types::Name)),
)
.about("Update a VPC") .about("Update a VPC")
} }
@ -2088,6 +2164,18 @@ impl Cli {
.required(true) .required(true)
.value_parser(clap::value_parser!(types::Name)), .value_parser(clap::value_parser!(types::Name)),
) )
.arg(
clap::Arg::new("description")
.long("description")
.required(false)
.value_parser(clap::value_parser!(String)),
)
.arg(
clap::Arg::new("name")
.long("name")
.required(false)
.value_parser(clap::value_parser!(types::Name)),
)
.about("Update a router") .about("Update a router")
} }
@ -2270,6 +2358,18 @@ impl Cli {
.required(true) .required(true)
.value_parser(clap::value_parser!(types::Name)), .value_parser(clap::value_parser!(types::Name)),
) )
.arg(
clap::Arg::new("description")
.long("description")
.required(false)
.value_parser(clap::value_parser!(String)),
)
.arg(
clap::Arg::new("name")
.long("name")
.required(false)
.value_parser(clap::value_parser!(types::Name)),
)
.about("Update a route") .about("Update a route")
} }
@ -2381,6 +2481,18 @@ impl Cli {
existing subnet in the VPC.", existing subnet in the VPC.",
), ),
) )
.arg(
clap::Arg::new("ipv6-block")
.long("ipv6-block")
.required(false)
.value_parser(clap::value_parser!(types::Ipv6Net))
.help(
"The IPv6 address range for this subnet.\n\nIt must be allocated from the \
RFC 4193 Unique Local Address range, with the prefix equal to the parent \
VPC's prefix. A random `/64` block will be assigned if one is not \
provided. It must not overlap with any existing subnet in the VPC.",
),
)
.arg( .arg(
clap::Arg::new("name") clap::Arg::new("name")
.long("name") .long("name")
@ -2445,6 +2557,18 @@ impl Cli {
.required(true) .required(true)
.value_parser(clap::value_parser!(types::Name)), .value_parser(clap::value_parser!(types::Name)),
) )
.arg(
clap::Arg::new("description")
.long("description")
.required(false)
.value_parser(clap::value_parser!(String)),
)
.arg(
clap::Arg::new("name")
.long("name")
.required(false)
.value_parser(clap::value_parser!(types::Name)),
)
.about("Update a subnet") .about("Update a subnet")
} }
@ -2983,6 +3107,18 @@ impl Cli {
.required(true) .required(true)
.value_parser(clap::value_parser!(types::Name)), .value_parser(clap::value_parser!(types::Name)),
) )
.arg(
clap::Arg::new("description")
.long("description")
.required(false)
.value_parser(clap::value_parser!(String)),
)
.arg(
clap::Arg::new("name")
.long("name")
.required(false)
.value_parser(clap::value_parser!(types::Name)),
)
.about("Update an IP Pool") .about("Update an IP Pool")
} }
@ -3169,6 +3305,20 @@ impl Cli {
pub fn cli_silo_create() -> clap::Command { pub fn cli_silo_create() -> clap::Command {
clap::Command::new("") clap::Command::new("")
.arg(
clap::Arg::new("admin-group-name")
.long("admin-group-name")
.required(false)
.value_parser(clap::value_parser!(String))
.help(
"If set, this group will be created during Silo creation and granted the \
\"Silo Admin\" role. Identity providers can assert that users belong to \
this group and those users can log in and further initialize the \
Silo.\n\nNote that if configuring a SAML based identity provider, \
group_attribute_name must be set for users to be considered part of a \
group. See [`SamlIdentityProviderCreate`] for more information.",
),
)
.arg( .arg(
clap::Arg::new("description") clap::Arg::new("description")
.long("description") .long("description")
@ -3331,6 +3481,17 @@ impl Cli {
.required(true) .required(true)
.value_parser(clap::value_parser!(String)), .value_parser(clap::value_parser!(String)),
) )
.arg(
clap::Arg::new("group-attribute-name")
.long("group-attribute-name")
.required(false)
.value_parser(clap::value_parser!(String))
.help(
"If set, SAML attributes with this name will be considered to denote a \
user's group membership, where the attribute value(s) should be a \
comma-separated list of group names.",
),
)
.arg( .arg(
clap::Arg::new("idp-entity-id") clap::Arg::new("idp-entity-id")
.long("idp-entity-id") .long("idp-entity-id")
@ -4094,6 +4255,18 @@ impl Cli {
.required(true) .required(true)
.value_parser(clap::value_parser!(types::NameOrId)), .value_parser(clap::value_parser!(types::NameOrId)),
) )
.arg(
clap::Arg::new("description")
.long("description")
.required(false)
.value_parser(clap::value_parser!(String)),
)
.arg(
clap::Arg::new("name")
.long("name")
.required(false)
.value_parser(clap::value_parser!(types::Name)),
)
.about("Update an organization") .about("Update an organization")
} }
@ -4208,6 +4381,18 @@ impl Cli {
.required(false) .required(false)
.value_parser(clap::value_parser!(types::NameOrId)), .value_parser(clap::value_parser!(types::NameOrId)),
) )
.arg(
clap::Arg::new("description")
.long("description")
.required(false)
.value_parser(clap::value_parser!(String)),
)
.arg(
clap::Arg::new("name")
.long("name")
.required(false)
.value_parser(clap::value_parser!(types::Name)),
)
.about("Update a project") .about("Update a project")
} }

View File

@ -27,7 +27,12 @@ impl Cli {
} }
pub fn cli_instance_ensure() -> clap::Command { pub fn cli_instance_ensure() -> clap::Command {
clap::Command::new("") clap::Command::new("").arg(
clap::Arg::new("cloud-init-bytes")
.long("cloud-init-bytes")
.required(false)
.value_parser(clap::value_parser!(String)),
)
} }
pub fn cli_instance_issue_crucible_snapshot_request() -> clap::Command { pub fn cli_instance_issue_crucible_snapshot_request() -> clap::Command {