clippy: remove unnecessary reference taking
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
parent
0a0f3906b5
commit
a81b2672d8
@ -80,7 +80,7 @@ impl<T> DeflateEncoder<T> {
|
|||||||
let old_out = self.compressor.total_out();
|
let old_out = self.compressor.total_out();
|
||||||
let res = self
|
let res = self
|
||||||
.compressor
|
.compressor
|
||||||
.compress(&inbuf[..], self.buffer.get_free_mut_slice(), flush)?;
|
.compress(inbuf, self.buffer.get_free_mut_slice(), flush)?;
|
||||||
let new_in = (self.compressor.total_in() - old_in) as usize;
|
let new_in = (self.compressor.total_in() - old_in) as usize;
|
||||||
let new_out = (self.compressor.total_out() - old_out) as usize;
|
let new_out = (self.compressor.total_out() - old_out) as usize;
|
||||||
self.buffer.add_size(new_out);
|
self.buffer.add_size(new_out);
|
||||||
|
@ -61,7 +61,7 @@ async fn handle_simple_command_future(
|
|||||||
let params = parse_arguments(prefix, cli_cmd, args)?;
|
let params = parse_arguments(prefix, cli_cmd, args)?;
|
||||||
|
|
||||||
match cli_cmd.info.handler {
|
match cli_cmd.info.handler {
|
||||||
ApiHandler::Sync(handler) => match (handler)(params, &cli_cmd.info, &mut rpcenv) {
|
ApiHandler::Sync(handler) => match (handler)(params, cli_cmd.info, &mut rpcenv) {
|
||||||
Ok(value) => {
|
Ok(value) => {
|
||||||
if value != Value::Null {
|
if value != Value::Null {
|
||||||
println!("Result: {}", serde_json::to_string_pretty(&value).unwrap());
|
println!("Result: {}", serde_json::to_string_pretty(&value).unwrap());
|
||||||
@ -73,7 +73,7 @@ async fn handle_simple_command_future(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
ApiHandler::Async(handler) => {
|
ApiHandler::Async(handler) => {
|
||||||
let future = (handler)(params, &cli_cmd.info, &mut rpcenv);
|
let future = (handler)(params, cli_cmd.info, &mut rpcenv);
|
||||||
|
|
||||||
match future.await {
|
match future.await {
|
||||||
Ok(value) => {
|
Ok(value) => {
|
||||||
@ -107,7 +107,7 @@ fn handle_simple_command(
|
|||||||
let params = parse_arguments(prefix, cli_cmd, args)?;
|
let params = parse_arguments(prefix, cli_cmd, args)?;
|
||||||
|
|
||||||
match cli_cmd.info.handler {
|
match cli_cmd.info.handler {
|
||||||
ApiHandler::Sync(handler) => match (handler)(params, &cli_cmd.info, &mut rpcenv) {
|
ApiHandler::Sync(handler) => match (handler)(params, cli_cmd.info, &mut rpcenv) {
|
||||||
Ok(value) => {
|
Ok(value) => {
|
||||||
if value != Value::Null {
|
if value != Value::Null {
|
||||||
println!("Result: {}", serde_json::to_string_pretty(&value).unwrap());
|
println!("Result: {}", serde_json::to_string_pretty(&value).unwrap());
|
||||||
@ -119,7 +119,7 @@ fn handle_simple_command(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
ApiHandler::Async(handler) => {
|
ApiHandler::Async(handler) => {
|
||||||
let future = (handler)(params, &cli_cmd.info, &mut rpcenv);
|
let future = (handler)(params, cli_cmd.info, &mut rpcenv);
|
||||||
if let Some(run) = run {
|
if let Some(run) = run {
|
||||||
match (run)(future) {
|
match (run)(future) {
|
||||||
Ok(value) => {
|
Ok(value) => {
|
||||||
@ -172,7 +172,7 @@ fn parse_nested_command<'a>(
|
|||||||
});
|
});
|
||||||
|
|
||||||
let err_msg = format!("no command specified.\nPossible commands: {}", list);
|
let err_msg = format!("no command specified.\nPossible commands: {}", list);
|
||||||
print_nested_usage_error(&prefix, map, &err_msg);
|
print_nested_usage_error(prefix, map, &err_msg);
|
||||||
return Err(format_err!("{}", err_msg));
|
return Err(format_err!("{}", err_msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,7 +182,7 @@ fn parse_nested_command<'a>(
|
|||||||
Some(cmd) => cmd,
|
Some(cmd) => cmd,
|
||||||
None => {
|
None => {
|
||||||
let err_msg = format!("no such command '{}'", command);
|
let err_msg = format!("no such command '{}'", command);
|
||||||
print_nested_usage_error(&prefix, map, &err_msg);
|
print_nested_usage_error(prefix, map, &err_msg);
|
||||||
return Err(format_err!("{}", err_msg));
|
return Err(format_err!("{}", err_msg));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -192,7 +192,7 @@ fn parse_nested_command<'a>(
|
|||||||
match sub_cmd {
|
match sub_cmd {
|
||||||
CommandLineInterface::Simple(cli_cmd) => {
|
CommandLineInterface::Simple(cli_cmd) => {
|
||||||
//return handle_simple_command(&prefix, cli_cmd, args).await;
|
//return handle_simple_command(&prefix, cli_cmd, args).await;
|
||||||
return Ok(&cli_cmd);
|
return Ok(cli_cmd);
|
||||||
}
|
}
|
||||||
CommandLineInterface::Nested(new_map) => map = new_map,
|
CommandLineInterface::Nested(new_map) => map = new_map,
|
||||||
}
|
}
|
||||||
@ -297,12 +297,12 @@ pub async fn handle_command_future(
|
|||||||
|
|
||||||
let result = match &*def {
|
let result = match &*def {
|
||||||
CommandLineInterface::Simple(ref cli_cmd) => {
|
CommandLineInterface::Simple(ref cli_cmd) => {
|
||||||
handle_simple_command_future(&prefix, &cli_cmd, args, rpcenv).await
|
handle_simple_command_future(prefix, cli_cmd, args, rpcenv).await
|
||||||
}
|
}
|
||||||
CommandLineInterface::Nested(ref map) => {
|
CommandLineInterface::Nested(ref map) => {
|
||||||
let mut prefix = prefix.to_string();
|
let mut prefix = prefix.to_string();
|
||||||
let cli_cmd = parse_nested_command(&mut prefix, &map, &mut args)?;
|
let cli_cmd = parse_nested_command(&mut prefix, map, &mut args)?;
|
||||||
handle_simple_command_future(&prefix, &cli_cmd, args, rpcenv).await
|
handle_simple_command_future(&prefix, cli_cmd, args, rpcenv).await
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -326,12 +326,12 @@ pub fn handle_command(
|
|||||||
|
|
||||||
let result = match &*def {
|
let result = match &*def {
|
||||||
CommandLineInterface::Simple(ref cli_cmd) => {
|
CommandLineInterface::Simple(ref cli_cmd) => {
|
||||||
handle_simple_command(&prefix, &cli_cmd, args, rpcenv, run)
|
handle_simple_command(prefix, cli_cmd, args, rpcenv, run)
|
||||||
}
|
}
|
||||||
CommandLineInterface::Nested(ref map) => {
|
CommandLineInterface::Nested(ref map) => {
|
||||||
let mut prefix = prefix.to_string();
|
let mut prefix = prefix.to_string();
|
||||||
let cli_cmd = parse_nested_command(&mut prefix, &map, &mut args)?;
|
let cli_cmd = parse_nested_command(&mut prefix, map, &mut args)?;
|
||||||
handle_simple_command(&prefix, &cli_cmd, args, rpcenv, run)
|
handle_simple_command(&prefix, cli_cmd, args, rpcenv, run)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -357,10 +357,10 @@ fn prepare_cli_command(def: &CommandLineInterface) -> (String, Vec<String>) {
|
|||||||
if args[0] == "printdoc" {
|
if args[0] == "printdoc" {
|
||||||
let usage = match def {
|
let usage = match def {
|
||||||
CommandLineInterface::Simple(cli_cmd) => {
|
CommandLineInterface::Simple(cli_cmd) => {
|
||||||
generate_usage_str(&prefix, &cli_cmd, DocumentationFormat::ReST, "", &[])
|
generate_usage_str(&prefix, cli_cmd, DocumentationFormat::ReST, "", &[])
|
||||||
}
|
}
|
||||||
CommandLineInterface::Nested(map) => {
|
CommandLineInterface::Nested(map) => {
|
||||||
generate_nested_usage(&prefix, &map, DocumentationFormat::ReST)
|
generate_nested_usage(&prefix, map, DocumentationFormat::ReST)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
println!("{}", usage);
|
println!("{}", usage);
|
||||||
|
@ -67,7 +67,7 @@ fn get_property_completion(
|
|||||||
}
|
}
|
||||||
Schema::Array(ArraySchema { items, .. }) => {
|
Schema::Array(ArraySchema { items, .. }) => {
|
||||||
if let Schema::String(_) = items {
|
if let Schema::String(_) = items {
|
||||||
return get_property_completion(&items, name, completion_functions, arg, param);
|
return get_property_completion(items, name, completion_functions, arg, param);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@ -101,7 +101,7 @@ fn get_simple_completion(
|
|||||||
record_done_argument(done, cli_cmd.info.parameters, prop_name, &args[0]);
|
record_done_argument(done, cli_cmd.info.parameters, prop_name, &args[0]);
|
||||||
if args.len() > 1 {
|
if args.len() > 1 {
|
||||||
if is_array_param {
|
if is_array_param {
|
||||||
return get_simple_completion(cli_cmd, done, &arg_param[..], &args[1..]);
|
return get_simple_completion(cli_cmd, done, arg_param, &args[1..]);
|
||||||
} else {
|
} else {
|
||||||
return get_simple_completion(cli_cmd, done, &arg_param[1..], &args[1..]);
|
return get_simple_completion(cli_cmd, done, &arg_param[1..], &args[1..]);
|
||||||
}
|
}
|
||||||
@ -153,7 +153,7 @@ fn get_simple_completion(
|
|||||||
schema,
|
schema,
|
||||||
prop_name,
|
prop_name,
|
||||||
&cli_cmd.completion_functions,
|
&cli_cmd.completion_functions,
|
||||||
&prefix,
|
prefix,
|
||||||
done,
|
done,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -223,9 +223,9 @@ impl CommandLineInterface {
|
|||||||
CommandLineInterface::Simple(cli_cmd) => {
|
CommandLineInterface::Simple(cli_cmd) => {
|
||||||
let mut done: HashMap<String, String> = HashMap::new();
|
let mut done: HashMap<String, String> = HashMap::new();
|
||||||
cli_cmd.fixed_param.iter().for_each(|(key, value)| {
|
cli_cmd.fixed_param.iter().for_each(|(key, value)| {
|
||||||
record_done_argument(&mut done, cli_cmd.info.parameters, &key, &value);
|
record_done_argument(&mut done, cli_cmd.info.parameters, key, value);
|
||||||
});
|
});
|
||||||
get_simple_completion(cli_cmd, &mut done, &cli_cmd.arg_param, args)
|
get_simple_completion(cli_cmd, &mut done, cli_cmd.arg_param, args)
|
||||||
}
|
}
|
||||||
CommandLineInterface::Nested(map) => {
|
CommandLineInterface::Nested(map) => {
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
|
@ -47,7 +47,7 @@ pub fn format_and_print_result_full(
|
|||||||
} else if output_format == "json" {
|
} else if output_format == "json" {
|
||||||
println!("{}", serde_json::to_string(&result).unwrap());
|
println!("{}", serde_json::to_string(&result).unwrap());
|
||||||
} else if output_format == "text" {
|
} else if output_format == "text" {
|
||||||
if let Err(err) = value_to_text(std::io::stdout(), result, &return_type.schema, options) {
|
if let Err(err) = value_to_text(std::io::stdout(), result, return_type.schema, options) {
|
||||||
eprintln!("unable to format result: {}", err);
|
eprintln!("unable to format result: {}", err);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -152,7 +152,7 @@ pub fn parse_arguments<T: AsRef<str>>(
|
|||||||
|
|
||||||
for i in 0..arg_param.len() {
|
for i in 0..arg_param.len() {
|
||||||
let name = arg_param[i];
|
let name = arg_param[i];
|
||||||
if let Some((optional, param_schema)) = schema.lookup(&name) {
|
if let Some((optional, param_schema)) = schema.lookup(name) {
|
||||||
if i == arg_param.len() - 1 {
|
if i == arg_param.len() - 1 {
|
||||||
last_arg_param_is_optional = optional;
|
last_arg_param_is_optional = optional;
|
||||||
if let Schema::Array(_) = param_schema {
|
if let Schema::Array(_) = param_schema {
|
||||||
@ -250,7 +250,7 @@ fn test_argument_paramenter() {
|
|||||||
let args = vec!["-enable", "local"];
|
let args = vec!["-enable", "local"];
|
||||||
let res = parse_arguments(
|
let res = parse_arguments(
|
||||||
&args,
|
&args,
|
||||||
&vec!["storage"],
|
&["storage"],
|
||||||
&HashMap::new(),
|
&HashMap::new(),
|
||||||
ParameterSchema::from(&PARAMETERS),
|
ParameterSchema::from(&PARAMETERS),
|
||||||
);
|
);
|
||||||
|
@ -476,7 +476,7 @@ fn format_table<W: Write>(
|
|||||||
let mut cells = Vec::new();
|
let mut cells = Vec::new();
|
||||||
for entry in list.iter() {
|
for entry in list.iter() {
|
||||||
let result = if let Some(renderer) = renderer {
|
let result = if let Some(renderer) = renderer {
|
||||||
(renderer)(&entry[name], &entry)
|
(renderer)(&entry[name], entry)
|
||||||
} else {
|
} else {
|
||||||
data_to_text(&entry[name], prop_schema)
|
data_to_text(&entry[name], prop_schema)
|
||||||
};
|
};
|
||||||
@ -691,7 +691,7 @@ fn format_object<W: Write>(
|
|||||||
});
|
});
|
||||||
|
|
||||||
let result = if let Some(renderer) = renderer {
|
let result = if let Some(renderer) = renderer {
|
||||||
(renderer)(&data[name], &data)
|
(renderer)(&data[name], data)
|
||||||
} else {
|
} else {
|
||||||
data_to_text(&data[name], prop_schema)
|
data_to_text(&data[name], prop_schema)
|
||||||
};
|
};
|
||||||
|
@ -14,7 +14,7 @@ fn dump_method_definition(method: &str, path: &str, def: Option<&ApiMethod>) ->
|
|||||||
match def {
|
match def {
|
||||||
None => None,
|
None => None,
|
||||||
Some(api_method) => {
|
Some(api_method) => {
|
||||||
let description = wrap_text("", "", &api_method.parameters.description(), 80);
|
let description = wrap_text("", "", api_method.parameters.description(), 80);
|
||||||
let param_descr = dump_properties(&api_method.parameters, "", style, &[]);
|
let param_descr = dump_properties(&api_method.parameters, "", style, &[]);
|
||||||
|
|
||||||
let return_descr = dump_api_return_schema(&api_method.returns, style);
|
let return_descr = dump_api_return_schema(&api_method.returns, style);
|
||||||
|
@ -96,7 +96,7 @@ pub fn check_api_permission(
|
|||||||
param: &HashMap<String, String>,
|
param: &HashMap<String, String>,
|
||||||
info: &dyn UserInformation,
|
info: &dyn UserInformation,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if let Some(ref userid) = userid {
|
if let Some(userid) = userid {
|
||||||
if info.is_superuser(userid) {
|
if info.is_superuser(userid) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -120,7 +120,7 @@ fn check_api_permission_tail(
|
|||||||
}
|
}
|
||||||
Permission::Superuser => match userid {
|
Permission::Superuser => match userid {
|
||||||
None => return false,
|
None => return false,
|
||||||
Some(ref userid) => return info.is_superuser(userid),
|
Some(userid) => return info.is_superuser(userid),
|
||||||
},
|
},
|
||||||
Permission::User(expected_userid) => match userid {
|
Permission::User(expected_userid) => match userid {
|
||||||
None => return false,
|
None => return false,
|
||||||
@ -133,7 +133,7 @@ fn check_api_permission_tail(
|
|||||||
},
|
},
|
||||||
Permission::Group(expected_group) => match userid {
|
Permission::Group(expected_group) => match userid {
|
||||||
None => return false,
|
None => return false,
|
||||||
Some(ref userid) => return info.is_group_member(userid, expected_group),
|
Some(userid) => return info.is_group_member(userid, expected_group),
|
||||||
},
|
},
|
||||||
Permission::WithParam(param_name, subtest) => {
|
Permission::WithParam(param_name, subtest) => {
|
||||||
return check_api_permission(
|
return check_api_permission(
|
||||||
|
@ -60,14 +60,14 @@ pub enum RpcEnvironmentType {
|
|||||||
impl core::ops::Index<&str> for &dyn RpcEnvironment {
|
impl core::ops::Index<&str> for &dyn RpcEnvironment {
|
||||||
type Output = Value;
|
type Output = Value;
|
||||||
fn index(&self, index: &str) -> &Value {
|
fn index(&self, index: &str) -> &Value {
|
||||||
&self.result_attrib().index(index)
|
self.result_attrib().index(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::ops::Index<&str> for &mut dyn RpcEnvironment {
|
impl core::ops::Index<&str> for &mut dyn RpcEnvironment {
|
||||||
type Output = Value;
|
type Output = Value;
|
||||||
fn index(&self, index: &str) -> &Value {
|
fn index(&self, index: &str) -> &Value {
|
||||||
&self.result_attrib().index(index)
|
self.result_attrib().index(index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,12 +113,12 @@ pub fn dump_properties(
|
|||||||
let mut optional_list: Vec<String> = Vec::new();
|
let mut optional_list: Vec<String> = Vec::new();
|
||||||
|
|
||||||
for (prop, optional, schema) in param.properties() {
|
for (prop, optional, schema) in param.properties() {
|
||||||
if skip.iter().find(|n| n == &prop).is_some() {
|
if skip.iter().any(|n| n == prop) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut param_descr =
|
let mut param_descr =
|
||||||
get_property_description(prop, &schema, style, DocumentationFormat::ReST);
|
get_property_description(prop, schema, style, DocumentationFormat::ReST);
|
||||||
|
|
||||||
if !indent.is_empty() {
|
if !indent.is_empty() {
|
||||||
param_descr = format!("{}{}", indent, param_descr); // indent first line
|
param_descr = format!("{}{}", indent, param_descr); // indent first line
|
||||||
|
@ -885,7 +885,7 @@ pub fn parse_property_string(value_str: &str, schema: &'static Schema) -> Result
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
for value in list {
|
for value in list {
|
||||||
match parse_simple_value(value.trim(), &array_schema.items) {
|
match parse_simple_value(value.trim(), array_schema.items) {
|
||||||
Ok(res) => array.push(res),
|
Ok(res) => array.push(res),
|
||||||
Err(err) => bail!("unable to parse array element: {}", err),
|
Err(err) => bail!("unable to parse array element: {}", err),
|
||||||
}
|
}
|
||||||
@ -951,7 +951,7 @@ fn do_parse_parameter_strings(
|
|||||||
let additional_properties = schema.additional_properties();
|
let additional_properties = schema.additional_properties();
|
||||||
|
|
||||||
for (key, value) in data {
|
for (key, value) in data {
|
||||||
if let Some((_optional, prop_schema)) = schema.lookup(&key) {
|
if let Some((_optional, prop_schema)) = schema.lookup(key) {
|
||||||
match prop_schema {
|
match prop_schema {
|
||||||
Schema::Array(array_schema) => {
|
Schema::Array(array_schema) => {
|
||||||
if params[key] == Value::Null {
|
if params[key] == Value::Null {
|
||||||
@ -959,7 +959,7 @@ fn do_parse_parameter_strings(
|
|||||||
}
|
}
|
||||||
match params[key] {
|
match params[key] {
|
||||||
Value::Array(ref mut array) => {
|
Value::Array(ref mut array) => {
|
||||||
match parse_simple_value(value, &array_schema.items) {
|
match parse_simple_value(value, array_schema.items) {
|
||||||
Ok(res) => array.push(res), // fixme: check_length??
|
Ok(res) => array.push(res), // fixme: check_length??
|
||||||
Err(err) => errors.push(key.into(), err),
|
Err(err) => errors.push(key.into(), err),
|
||||||
}
|
}
|
||||||
@ -1031,11 +1031,11 @@ pub fn verify_json(data: &Value, schema: &Schema) -> Result<(), Error> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Schema::Object(object_schema) => verify_json_object(data, object_schema)?,
|
Schema::Object(object_schema) => verify_json_object(data, object_schema)?,
|
||||||
Schema::Array(array_schema) => verify_json_array(data, &array_schema)?,
|
Schema::Array(array_schema) => verify_json_array(data, array_schema)?,
|
||||||
Schema::Boolean(boolean_schema) => verify_json_boolean(data, &boolean_schema)?,
|
Schema::Boolean(boolean_schema) => verify_json_boolean(data, boolean_schema)?,
|
||||||
Schema::Integer(integer_schema) => verify_json_integer(data, &integer_schema)?,
|
Schema::Integer(integer_schema) => verify_json_integer(data, integer_schema)?,
|
||||||
Schema::Number(number_schema) => verify_json_number(data, &number_schema)?,
|
Schema::Number(number_schema) => verify_json_number(data, number_schema)?,
|
||||||
Schema::String(string_schema) => verify_json_string(data, &string_schema)?,
|
Schema::String(string_schema) => verify_json_string(data, string_schema)?,
|
||||||
Schema::AllOf(all_of_schema) => verify_json_object(data, all_of_schema)?,
|
Schema::AllOf(all_of_schema) => verify_json_object(data, all_of_schema)?,
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -1087,7 +1087,7 @@ pub fn verify_json_array(data: &Value, schema: &ArraySchema) -> Result<(), Error
|
|||||||
schema.check_length(list.len())?;
|
schema.check_length(list.len())?;
|
||||||
|
|
||||||
for (i, item) in list.iter().enumerate() {
|
for (i, item) in list.iter().enumerate() {
|
||||||
let result = verify_json(item, &schema.items);
|
let result = verify_json(item, schema.items);
|
||||||
if let Err(err) = result {
|
if let Err(err) = result {
|
||||||
let mut errors = ParameterError::new();
|
let mut errors = ParameterError::new();
|
||||||
errors.add_errors(&format!("[{}]", i), err);
|
errors.add_errors(&format!("[{}]", i), err);
|
||||||
@ -1111,7 +1111,7 @@ pub fn verify_json_object(data: &Value, schema: &dyn ObjectSchemaType) -> Result
|
|||||||
let additional_properties = schema.additional_properties();
|
let additional_properties = schema.additional_properties();
|
||||||
|
|
||||||
for (key, value) in map {
|
for (key, value) in map {
|
||||||
if let Some((_optional, prop_schema)) = schema.lookup(&key) {
|
if let Some((_optional, prop_schema)) = schema.lookup(key) {
|
||||||
let result = match prop_schema {
|
let result = match prop_schema {
|
||||||
Schema::Object(object_schema) => verify_json_object(value, object_schema),
|
Schema::Object(object_schema) => verify_json_object(value, object_schema),
|
||||||
Schema::Array(array_schema) => verify_json_array(value, array_schema),
|
Schema::Array(array_schema) => verify_json_array(value, array_schema),
|
||||||
|
@ -66,7 +66,7 @@ impl SectionConfigPlugin {
|
|||||||
pub fn get_id_schema(&self) -> Option<&Schema> {
|
pub fn get_id_schema(&self) -> Option<&Schema> {
|
||||||
match &self.id_property {
|
match &self.id_property {
|
||||||
Some(id_prop) => {
|
Some(id_prop) => {
|
||||||
if let Some((_, schema)) = self.properties.lookup(&id_prop) {
|
if let Some((_, schema)) = self.properties.lookup(id_prop) {
|
||||||
Some(schema)
|
Some(schema)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@ -325,7 +325,7 @@ impl SectionConfig {
|
|||||||
let plugin = self.plugins.get(type_name).unwrap();
|
let plugin = self.plugins.get(type_name).unwrap();
|
||||||
|
|
||||||
let id_schema = plugin.get_id_schema().unwrap_or(self.id_schema);
|
let id_schema = plugin.get_id_schema().unwrap_or(self.id_schema);
|
||||||
if let Err(err) = parse_simple_value(§ion_id, &id_schema) {
|
if let Err(err) = parse_simple_value(section_id, id_schema) {
|
||||||
bail!("syntax error in section identifier: {}", err.to_string());
|
bail!("syntax error in section identifier: {}", err.to_string());
|
||||||
}
|
}
|
||||||
if section_id.chars().any(|c| c.is_control()) {
|
if section_id.chars().any(|c| c.is_control()) {
|
||||||
@ -402,7 +402,7 @@ impl SectionConfig {
|
|||||||
(self.parse_section_header)(line)
|
(self.parse_section_header)(line)
|
||||||
{
|
{
|
||||||
//println!("OKLINE: type: {} ID: {}", section_type, section_id);
|
//println!("OKLINE: type: {} ID: {}", section_type, section_id);
|
||||||
if let Some(ref plugin) = self.plugins.get(§ion_type) {
|
if let Some(plugin) = self.plugins.get(§ion_type) {
|
||||||
let id_schema =
|
let id_schema =
|
||||||
plugin.get_id_schema().unwrap_or(self.id_schema);
|
plugin.get_id_schema().unwrap_or(self.id_schema);
|
||||||
if let Err(err) = parse_simple_value(§ion_id, id_schema) {
|
if let Err(err) = parse_simple_value(§ion_id, id_schema) {
|
||||||
@ -480,12 +480,12 @@ impl SectionConfig {
|
|||||||
if let ParseState::InsideSection(plugin, ref mut section_id, ref mut config) = state
|
if let ParseState::InsideSection(plugin, ref mut section_id, ref mut config) = state
|
||||||
{
|
{
|
||||||
// finish section
|
// finish section
|
||||||
test_required_properties(&config, plugin.properties, &plugin.id_property)?;
|
test_required_properties(config, plugin.properties, &plugin.id_property)?;
|
||||||
if let Some(id_property) = &plugin.id_property {
|
if let Some(id_property) = &plugin.id_property {
|
||||||
config[id_property] = Value::from(section_id.clone());
|
config[id_property] = Value::from(section_id.clone());
|
||||||
}
|
}
|
||||||
result.set_data(§ion_id, &plugin.type_name, config)?;
|
result.set_data(section_id, &plugin.type_name, config)?;
|
||||||
result.record_order(§ion_id);
|
result.record_order(section_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -756,7 +756,7 @@ lvmthin: local-lvm2
|
|||||||
content rootdir,images
|
content rootdir,images
|
||||||
";
|
";
|
||||||
|
|
||||||
let res = config.parse(filename, &raw);
|
let res = config.parse(filename, raw);
|
||||||
println!("RES: {:?}", res);
|
println!("RES: {:?}", res);
|
||||||
let raw = config.write(filename, &res.unwrap());
|
let raw = config.write(filename, &res.unwrap());
|
||||||
println!("CONFIG:\n{}", raw.unwrap());
|
println!("CONFIG:\n{}", raw.unwrap());
|
||||||
@ -827,7 +827,7 @@ group: mygroup
|
|||||||
comment a very important group
|
comment a very important group
|
||||||
";
|
";
|
||||||
|
|
||||||
let res = config.parse(filename, &raw);
|
let res = config.parse(filename, raw);
|
||||||
println!("RES: {:?}", res);
|
println!("RES: {:?}", res);
|
||||||
let raw = config.write(filename, &res.unwrap());
|
let raw = config.write(filename, &res.unwrap());
|
||||||
println!("CONFIG:\n{}", raw.unwrap());
|
println!("CONFIG:\n{}", raw.unwrap());
|
||||||
@ -876,7 +876,7 @@ lvmthin: local-lvm2
|
|||||||
thinpool data
|
thinpool data
|
||||||
";
|
";
|
||||||
|
|
||||||
let res = config.parse(filename, &raw);
|
let res = config.parse(filename, raw);
|
||||||
println!("RES: {:?}", res);
|
println!("RES: {:?}", res);
|
||||||
let created = config
|
let created = config
|
||||||
.write(filename, &res.unwrap())
|
.write(filename, &res.unwrap())
|
||||||
|
Loading…
Reference in New Issue
Block a user