mirror of
https://git.proxmox.com/git/proxmox
synced 2025-05-29 17:15:57 +00:00
formatting fixup
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
d966061f54
commit
099efb2da5
@ -197,7 +197,8 @@ impl<T: ApiType> ApiType for Option<T> {
|
|||||||
DATA.once.call_once(|| {
|
DATA.once.call_once(|| {
|
||||||
let info = T::type_info();
|
let info = T::type_info();
|
||||||
DATA.name.set(Some(format!("optional: {}", info.name)));
|
DATA.name.set(Some(format!("optional: {}", info.name)));
|
||||||
DATA.description.set(Some(format!("optional: {}", info.description)));
|
DATA.description
|
||||||
|
.set(Some(format!("optional: {}", info.description)));
|
||||||
DATA.info.set(Some(TypeInfo {
|
DATA.info.set(Some(TypeInfo {
|
||||||
name: unsafe { (*DATA.name.as_ptr()).as_ref().unwrap().as_str() },
|
name: unsafe { (*DATA.name.as_ptr()).as_ref().unwrap().as_str() },
|
||||||
description: unsafe { (*DATA.description.as_ptr()).as_ref().unwrap().as_str() },
|
description: unsafe { (*DATA.description.as_ptr()).as_ref().unwrap().as_str() },
|
||||||
|
@ -19,7 +19,11 @@ fn simple() {
|
|||||||
|
|
||||||
check_cli(&cli, &["new", "--foo=FOO", "--bar=BAR"], Ok("FOO:BAR"));
|
check_cli(&cli, &["new", "--foo=FOO", "--bar=BAR"], Ok("FOO:BAR"));
|
||||||
check_cli(&cli, &["new", "--foo", "FOO", "--bar=BAR"], Ok("FOO:BAR"));
|
check_cli(&cli, &["new", "--foo", "FOO", "--bar=BAR"], Ok("FOO:BAR"));
|
||||||
check_cli(&cli, &["new", "--foo", "FOO", "--bar", "BAR"], Ok("FOO:BAR"));
|
check_cli(
|
||||||
|
&cli,
|
||||||
|
&["new", "--foo", "FOO", "--bar", "BAR"],
|
||||||
|
Ok("FOO:BAR"),
|
||||||
|
);
|
||||||
check_cli(&cli, &["new", "--foo=FOO"], Err("missing parameter: 'bar'"));
|
check_cli(&cli, &["new", "--foo=FOO"], Err("missing parameter: 'bar'"));
|
||||||
check_cli(&cli, &["new", "--bar=BAR"], Err("missing parameter: 'foo'"));
|
check_cli(&cli, &["new", "--bar=BAR"], Err("missing parameter: 'foo'"));
|
||||||
check_cli(&cli, &["new"], Err("missing parameter: 'foo'"));
|
check_cli(&cli, &["new"], Err("missing parameter: 'foo'"));
|
||||||
@ -27,14 +31,26 @@ fn simple() {
|
|||||||
check_cli(&cli, &["newfoo", "POSFOO"], Err("missing parameter: 'bar'"));
|
check_cli(&cli, &["newfoo", "POSFOO"], Err("missing parameter: 'bar'"));
|
||||||
check_cli(&cli, &["newfoo", "POSFOO", "--bar=BAR"], Ok("POSFOO:BAR"));
|
check_cli(&cli, &["newfoo", "POSFOO", "--bar=BAR"], Ok("POSFOO:BAR"));
|
||||||
check_cli(&cli, &["newfoo", "--bar=BAR", "POSFOO"], Ok("POSFOO:BAR"));
|
check_cli(&cli, &["newfoo", "--bar=BAR", "POSFOO"], Ok("POSFOO:BAR"));
|
||||||
check_cli(&cli, &["newfoo", "--bar=BAR"], Err("missing positional parameters: foo"));
|
check_cli(
|
||||||
|
&cli,
|
||||||
|
&["newfoo", "--bar=BAR"],
|
||||||
|
Err("missing positional parameters: foo"),
|
||||||
|
);
|
||||||
|
|
||||||
check_cli(&cli, &["newbar", "POSBAR"], Err("missing parameter: 'foo'"));
|
check_cli(&cli, &["newbar", "POSBAR"], Err("missing parameter: 'foo'"));
|
||||||
check_cli(&cli, &["newbar", "POSBAR", "--foo=ABC"], Ok("ABC:POSBAR"));
|
check_cli(&cli, &["newbar", "POSBAR", "--foo=ABC"], Ok("ABC:POSBAR"));
|
||||||
check_cli(&cli, &["newbar", "--foo=ABC", "POSBAR"], Ok("ABC:POSBAR"));
|
check_cli(&cli, &["newbar", "--foo=ABC", "POSBAR"], Ok("ABC:POSBAR"));
|
||||||
check_cli(&cli, &["newbar", "--foo=ABC"], Err("missing positional parameters: bar"));
|
check_cli(
|
||||||
|
&cli,
|
||||||
|
&["newbar", "--foo=ABC"],
|
||||||
|
Err("missing positional parameters: bar"),
|
||||||
|
);
|
||||||
|
|
||||||
check_cli(&cli, &["newfoo", "FOO1", "--foo=FOO2", "--bar=BAR", "--baz=OMG"], Ok("FOO2:BAR:OMG"));
|
check_cli(
|
||||||
|
&cli,
|
||||||
|
&["newfoo", "FOO1", "--foo=FOO2", "--bar=BAR", "--baz=OMG"],
|
||||||
|
Ok("FOO2:BAR:OMG"),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_cli(cli: &cli::App<Bytes>, args: &[&str], expect: Result<&str, &str>) {
|
fn check_cli(cli: &cli::App<Bytes>, args: &[&str], expect: Result<&str, &str>) {
|
||||||
@ -48,15 +64,19 @@ fn check_cli(cli: &cli::App<Bytes>, args: &[&str], expect: Result<&str, &str>) {
|
|||||||
let result = result.to_string();
|
let result = result.to_string();
|
||||||
assert_eq!(result, expected, "expected specific error message");
|
assert_eq!(result, expected, "expected specific error message");
|
||||||
}
|
}
|
||||||
(Ok(result), Err(err)) => {
|
(Ok(result), Err(err)) => match std::str::from_utf8(result.body().as_ref()) {
|
||||||
match std::str::from_utf8(result.body().as_ref()) {
|
Ok(value) => panic!(
|
||||||
Ok(value) => panic!("expected error '{}', got success with value '{}'", err, value),
|
"expected error '{}', got success with value '{}'",
|
||||||
Err(_) => panic!("expected error '{}', got success with non-utf8 string", err),
|
err, value
|
||||||
}
|
),
|
||||||
}
|
Err(_) => panic!("expected error '{}', got success with non-utf8 string", err),
|
||||||
|
},
|
||||||
(Err(err), Ok(expected)) => {
|
(Err(err), Ok(expected)) => {
|
||||||
let err = err.to_string();
|
let err = err.to_string();
|
||||||
panic!("expected success with value '{}', got error '{}'", expected, err);
|
panic!(
|
||||||
|
"expected success with value '{}', got error '{}'",
|
||||||
|
expected, err
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,7 +91,9 @@ mod methods {
|
|||||||
use proxmox_api::{get_type_info, ApiFuture, ApiMethod, ApiOutput, ApiType, Parameter};
|
use proxmox_api::{get_type_info, ApiFuture, ApiMethod, ApiOutput, ApiType, Parameter};
|
||||||
|
|
||||||
fn required_str<'a>(value: &'a Value, name: &'static str) -> Result<&'a str, Error> {
|
fn required_str<'a>(value: &'a Value, name: &'static str) -> Result<&'a str, Error> {
|
||||||
value[name].as_str().ok_or_else(|| format_err!("missing parameter: '{}'", name))
|
value[name]
|
||||||
|
.as_str()
|
||||||
|
.ok_or_else(|| format_err!("missing parameter: '{}'", name))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn simple_method(value: Value) -> ApiOutput<Bytes> {
|
pub async fn simple_method(value: Value) -> ApiOutput<Bytes> {
|
||||||
@ -80,7 +102,11 @@ mod methods {
|
|||||||
|
|
||||||
let baz = value
|
let baz = value
|
||||||
.get("baz")
|
.get("baz")
|
||||||
.map(|value| value.as_str().ok_or_else(|| format_err!("'baz' must be a string")))
|
.map(|value| {
|
||||||
|
value
|
||||||
|
.as_str()
|
||||||
|
.ok_or_else(|| format_err!("'baz' must be a string"))
|
||||||
|
})
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
|
|
||||||
let output = match baz {
|
let output = match baz {
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
use failure::*;
|
use failure::*;
|
||||||
|
|
||||||
pub mod io;
|
pub mod io;
|
||||||
pub mod vec;
|
|
||||||
pub mod serde;
|
pub mod serde;
|
||||||
|
pub mod vec;
|
||||||
|
|
||||||
/// Evaluates to the offset (in bytes) of a given member within a struct
|
/// Evaluates to the offset (in bytes) of a given member within a struct
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
Loading…
Reference in New Issue
Block a user