Skip to content
This repository was archived by the owner on Jul 17, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ regex = "1"
num-traits = "^0.2.14"
oauth2 = "4.1"
open = "^2.1.1"
oxide-api = "0.1.0-rc.40"
oxide-api = "0.1.0-rc.41"
#oxide-api = { path= "../oxide.rs/oxide" }
parse-display = "^0.5.5"
pulldown-cmark = "^0.9.1"
Expand Down
33 changes: 30 additions & 3 deletions cli-macro-impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ struct Property {
schema: openapiv3::ReferenceOr<openapiv3::Schema>,
required: bool,
description: Option<String>,
default: Option<serde_json::Value>,
}

struct Parameter {
Expand Down Expand Up @@ -745,6 +746,7 @@ impl Operation {
required: obj.required.contains(&key)
|| obj.required.contains(&key.trim_start_matches("new_").to_string()),
description: s.schema_data.description,
default: s.schema_data.default,
},
);
}
Expand Down Expand Up @@ -938,6 +940,7 @@ impl Operation {
schema: openapiv3::ReferenceOr<T>,
description: Option<String>,
required: bool,
default: Option<serde_json::Value>,
) -> Result<TokenStream> {
if skip_defaults(name, tag)
|| name == format!("{}_name", singular(tag))
Expand Down Expand Up @@ -1022,9 +1025,33 @@ impl Operation {
quote! {
#[clap(#long_flag, #short_flag multiple_values = true)]
}
} else if rendered == "bool" {
// Clap treats bools as flags, so any value passed is ignored
// just whether the argument is present or not is used.
// So if a default value of true is passed, there's no way to
// set the flag to false. We use `parse(try_from_str)` to
// allow passing true or false as the value.
// To also allow passing the flag without a value, we use
// `default_missing_value`.
// Perhaps we could be smart and generate --foo / --no-foo?
let default = default
.map(|d| d.to_string())
.map(|d| quote! {
parse(try_from_str), default_value = #d, default_missing_value = #d
})
.unwrap_or_else(|| quote! { });

quote! {
#[clap(#long_flag, #short_flag #default)]
}
} else {
let default = default
.map(|d| d.to_string())
.map(|d| quote! { default_value = #d })
.unwrap_or_else(|| quote! { default_value_t });

quote! {
#[clap(#long_flag, #short_flag default_value_t)]
#[clap(#long_flag, #short_flag #default)]
}
}
} else {
Expand Down Expand Up @@ -1054,11 +1081,11 @@ impl Operation {
// Let's get the type.
let schema = data.format.schema()?;

params.push(self.render_struct_param(&param, tag, schema, data.description, p.required)?);
params.push(self.render_struct_param(&param, tag, schema, data.description, p.required, None)?);
}

for (param, p) in self.get_request_body_properties()? {
params.push(self.render_struct_param(&param, tag, p.schema, p.description, p.required)?);
params.push(self.render_struct_param(&param, tag, p.schema, p.description, p.required, p.default)?);
}

Ok(params)
Expand Down
12 changes: 11 additions & 1 deletion cli-macro-impl/tests/gen/instances.rs.gen
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,17 @@ pub struct CmdInstanceCreate {
#[doc = "The network interfaces to be created for this instance."]
#[clap(long = "network-interfaces", short = 'n')]
pub network_interfaces: Option<oxide_api::types::InstanceNetworkInterfaceAttachment>,
#[doc = "Should this instance be started upon creation; true by default."]
#[clap(
long = "start",
short = 's',
parse(try_from_str),
default_value = "true",
default_missing_value = "true"
)]
pub start: bool,
#[doc = "User data for instance initialization systems (such as cloud-init). Must be a Base64-encoded string, as specified in RFC 4648 § 4 (+ and / characters with padding). Maximum 32 KiB unencoded data."]
#[clap(long = "user-data", short = 'u', default_value_t)]
#[clap(long = "user-data", short = 'u', default_value = "\"\"")]
pub user_data: String,
}

Expand Down Expand Up @@ -273,6 +282,7 @@ impl crate::cmd::Command for CmdInstanceCreate {
name: instance.clone(),
ncpus: ncpus.clone(),
network_interfaces: self.network_interfaces.clone(),
start: self.start.clone(),
user_data: self.user_data.clone(),
},
)
Expand Down
5 changes: 5 additions & 0 deletions docs/oxide.json
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,11 @@
"long": "network-interfaces",
"help": "The network interfaces to be created for this instance"
},
{
"short": "s",
"long": "start",
"help": "Should this instance be started upon creation; true by default"
},
{
"short": "u",
"long": "user-data",
Expand Down
7 changes: 6 additions & 1 deletion spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -8782,6 +8782,11 @@
}
]
},
"start": {
"description": "Should this instance be started upon creation; true by default.",
"default": true,
"type": "boolean"
},
"user_data": {
"description": "User data for instance initialization systems (such as cloud-init). Must be a Base64-encoded string, as specified in RFC 4648 § 4 (+ and / characters with padding). Maximum 32 KiB unencoded data.",
"default": "",
Expand Down Expand Up @@ -12142,4 +12147,4 @@
}
}
]
}
}
6 changes: 6 additions & 0 deletions src/cmd_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ mod test {
disks: Default::default(),
user_data: "some data".to_string(),
external_ips: Vec::from(["mypool".to_string()]),
start: true,
}),

stdin: "".to_string(),
Expand All @@ -578,6 +579,7 @@ mod test {
disks: Default::default(),
user_data: "some data".to_string(),
external_ips: Vec::from(["mypool".to_string()]),
start: true,
}),

stdin: "".to_string(),
Expand All @@ -598,6 +600,7 @@ mod test {
disks: Default::default(),
user_data: "some data".to_string(),
external_ips: Vec::from(["mypool".to_string()]),
start: true,
}),

stdin: "".to_string(),
Expand All @@ -618,6 +621,7 @@ mod test {
disks: Default::default(),
user_data: "some data".to_string(),
external_ips: Vec::from(["mypool".to_string()]),
start: true,
}),

stdin: "".to_string(),
Expand All @@ -638,6 +642,7 @@ mod test {
disks: Default::default(),
user_data: "some data".to_string(),
external_ips: Vec::from(["mypool".to_string()]),
start: true,
}),

stdin: "".to_string(),
Expand All @@ -658,6 +663,7 @@ mod test {
disks: Default::default(),
user_data: "some data".to_string(),
external_ips: Vec::from(["mypool".to_string()]),
start: true,
}),

stdin: "".to_string(),
Expand Down