Skip to content

Commit

Permalink
fix latest clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveL-MSFT committed Dec 3, 2024
1 parent e938212 commit 3d15939
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 72 deletions.
2 changes: 1 addition & 1 deletion dsc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn main() {
exit(util::EXIT_JSON_ERROR);
}
};
util::write_output(&json, &format);
util::write_output(&json, format.as_ref());
},
}

Expand Down
12 changes: 6 additions & 6 deletions dsc/src/resource_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn get(dsc: &DscManager, resource_type: &str, mut input: String, format: &Op
exit(EXIT_JSON_ERROR);
}
};
write_output(&json, format);
write_output(&json, format.as_ref());
}
Err(err) => {
error!("Error: {err}");
Expand Down Expand Up @@ -100,7 +100,7 @@ pub fn get_all(dsc: &DscManager, resource_type: &str, format: &Option<OutputForm
exit(EXIT_JSON_ERROR);
}
};
write_output(&json, format);
write_output(&json, format.as_ref());
}
}

Expand Down Expand Up @@ -141,7 +141,7 @@ pub fn set(dsc: &DscManager, resource_type: &str, mut input: String, format: &Op
exit(EXIT_JSON_ERROR);
}
};
write_output(&json, format);
write_output(&json, format.as_ref());
}
Err(err) => {
error!("Error: {err}");
Expand Down Expand Up @@ -187,7 +187,7 @@ pub fn test(dsc: &DscManager, resource_type: &str, mut input: String, format: &O
exit(EXIT_JSON_ERROR);
}
};
write_output(&json, format);
write_output(&json, format.as_ref());
}
Err(err) => {
error!("Error: {err}");
Expand Down Expand Up @@ -247,7 +247,7 @@ pub fn schema(dsc: &DscManager, resource_type: &str, format: &Option<OutputForma
exit(EXIT_JSON_ERROR);
}
};
write_output(&json, format);
write_output(&json, format.as_ref());
}
Err(err) => {
error!("Error: {err}");
Expand Down Expand Up @@ -293,7 +293,7 @@ pub fn export(dsc: &mut DscManager, resource_type: &str, format: &Option<OutputF
exit(EXIT_JSON_ERROR);
}
};
write_output(&json, format);
write_output(&json, format.as_ref());
}

#[must_use]
Expand Down
36 changes: 18 additions & 18 deletions dsc/src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn config_get(configurator: &mut Configurator, format: &Option<OutputFormat>
exit(EXIT_JSON_ERROR);
}
};
write_output(&json, format);
write_output(&json, format.as_ref());
}
else {
let json = match serde_json::to_string(&result) {
Expand All @@ -53,7 +53,7 @@ pub fn config_get(configurator: &mut Configurator, format: &Option<OutputFormat>
exit(EXIT_JSON_ERROR);
}
};
write_output(&json, format);
write_output(&json, format.as_ref());
if result.had_errors {
exit(EXIT_DSC_ERROR);
}
Expand All @@ -78,7 +78,7 @@ pub fn config_set(configurator: &mut Configurator, format: &Option<OutputFormat>
exit(EXIT_JSON_ERROR);
}
};
write_output(&json, format);
write_output(&json, format.as_ref());
}
else {
let json = match serde_json::to_string(&result) {
Expand All @@ -88,7 +88,7 @@ pub fn config_set(configurator: &mut Configurator, format: &Option<OutputFormat>
exit(EXIT_JSON_ERROR);
}
};
write_output(&json, format);
write_output(&json, format.as_ref());
if result.had_errors {
exit(EXIT_DSC_ERROR);
}
Expand Down Expand Up @@ -164,7 +164,7 @@ pub fn config_test(configurator: &mut Configurator, format: &Option<OutputFormat
}
}
};
write_output(&json, format);
write_output(&json, format.as_ref());
}
else {
let json = match serde_json::to_string(&result) {
Expand All @@ -174,7 +174,7 @@ pub fn config_test(configurator: &mut Configurator, format: &Option<OutputFormat
exit(EXIT_JSON_ERROR);
}
};
write_output(&json, format);
write_output(&json, format.as_ref());
if result.had_errors {
exit(EXIT_DSC_ERROR);
}
Expand All @@ -198,7 +198,7 @@ pub fn config_export(configurator: &mut Configurator, format: &Option<OutputForm
exit(EXIT_JSON_ERROR);
}
};
write_output(&json, format);
write_output(&json, format.as_ref());
if result.had_errors {

for msg in result.messages
Expand All @@ -216,7 +216,7 @@ pub fn config_export(configurator: &mut Configurator, format: &Option<OutputForm
}
}

fn initialize_config_root(path: &Option<String>) -> Option<String> {
fn initialize_config_root(path: Option<&String>) -> Option<String> {
// code that calls this pass in either None, Some("-"), or Some(path)
// in the case of `-` we treat it as None, but need to pass it back as subsequent processing needs to handle it
let use_stdin = if let Some(specified_path) = path {
Expand Down Expand Up @@ -254,7 +254,7 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option<String>, as_gro
ConfigSubCommand::Test { input, file, .. } |
ConfigSubCommand::Validate { input, file, .. } |
ConfigSubCommand::Export { input, file, .. } => {
let new_path = initialize_config_root(file);
let new_path = initialize_config_root(file.as_ref());
let document = get_input(input, &new_path);
if *as_include {
let (new_parameters, config_json) = match get_contents(&document) {
Expand All @@ -270,7 +270,7 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option<String>, as_gro
}
},
ConfigSubCommand::Resolve { input, file, .. } => {
let new_path = initialize_config_root(file);
let new_path = initialize_config_root(file.as_ref());
let document = get_input(input, &new_path);
let (new_parameters, config_json) = match get_contents(&document) {
Ok((parameters, config_json)) => (parameters, config_json),
Expand Down Expand Up @@ -331,7 +331,7 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option<String>, as_gro
}
};

if let Err(err) = configurator.set_context(&parameters) {
if let Err(err) = configurator.set_context(parameters.as_ref()) {
error!("Error: Parameter input failure: {err}");
exit(EXIT_INVALID_INPUT);
}
Expand All @@ -352,7 +352,7 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option<String>, as_gro
reason: None,
};
if *as_include {
let new_path = initialize_config_root(file);
let new_path = initialize_config_root(file.as_ref());
let input = get_input(input, &new_path);
match serde_json::from_str::<Include>(&input) {
Ok(_) => {
Expand Down Expand Up @@ -380,7 +380,7 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option<String>, as_gro
exit(EXIT_JSON_ERROR);
};

write_output(&json, format);
write_output(&json, format.as_ref());
},
ConfigSubCommand::Export { output_format, .. } => {
config_export(&mut configurator, output_format);
Expand Down Expand Up @@ -414,7 +414,7 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option<String>, as_gro
exit(EXIT_JSON_ERROR);
}
};
write_output(&json_string, output_format);
write_output(&json_string, output_format.as_ref());
},
}
}
Expand Down Expand Up @@ -520,7 +520,7 @@ pub fn resource(subcommand: &ResourceSubCommand) {

match subcommand {
ResourceSubCommand::List { resource_name, adapter_name, description, tags, output_format } => {
list_resources(&mut dsc, resource_name, adapter_name, description, tags, output_format);
list_resources(&mut dsc, resource_name.as_ref(), adapter_name.as_ref(), description.as_ref(), tags.as_ref(), output_format.as_ref());
},
ResourceSubCommand::Schema { resource , output_format } => {
dsc.find_resources(&[resource.to_string()]);
Expand Down Expand Up @@ -556,14 +556,14 @@ pub fn resource(subcommand: &ResourceSubCommand) {
}
}

fn list_resources(dsc: &mut DscManager, resource_name: &Option<String>, adapter_name: &Option<String>, description: &Option<String>, tags: &Option<Vec<String>>, format: &Option<OutputFormat>) {
fn list_resources(dsc: &mut DscManager, resource_name: Option<&String>, adapter_name: Option<&String>, description: Option<&String>, tags: Option<&Vec<String>>, format: Option<&OutputFormat>) {
let mut write_table = false;
let mut table = Table::new(&["Type", "Kind", "Version", "Caps", "RequireAdapter", "Description"]);
if format.is_none() && io::stdout().is_terminal() {
// write as table if format is not specified and interactive
write_table = true;
}
for resource in dsc.list_available_resources(&resource_name.clone().unwrap_or("*".to_string()), &adapter_name.clone().unwrap_or_default()) {
for resource in dsc.list_available_resources(resource_name.unwrap_or(&String::from("*")), adapter_name.unwrap_or(&String::from("*"))) {
let mut capabilities = "--------".to_string();
let capability_types = [
(Capability::Get, "g"),
Expand Down Expand Up @@ -594,7 +594,7 @@ fn list_resources(dsc: &mut DscManager, resource_name: &Option<String>, adapter_

// if description is specified, skip if resource description does not contain it
if description.is_some() &&
(manifest.description.is_none() | !manifest.description.unwrap_or_default().to_lowercase().contains(&description.as_ref().unwrap_or(&String::new()).to_lowercase())) {
(manifest.description.is_none() | !manifest.description.unwrap_or_default().to_lowercase().contains(&description.as_ref().unwrap_or(&&String::new()).to_lowercase())) {
continue;
}

Expand Down
8 changes: 4 additions & 4 deletions dsc/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,18 @@ pub fn get_schema(dsc_type: DscType) -> RootSchema {
///
/// * `json` - The JSON to write
/// * `format` - The format to use
pub fn write_output(json: &str, format: &Option<OutputFormat>) {
pub fn write_output(json: &str, format: Option<&OutputFormat>) {
let mut is_json = true;
let mut output_format = format.clone();
let mut output_format = format;
let mut syntax_color = false;
if std::io::stdout().is_terminal() {
syntax_color = true;
if output_format.is_none() {
output_format = Some(OutputFormat::Yaml);
output_format = Some(&OutputFormat::Yaml);
}
}
else if output_format.is_none() {
output_format = Some(OutputFormat::Json);
output_format = Some(&OutputFormat::Json);
}

let output = match output_format {
Expand Down
22 changes: 11 additions & 11 deletions dsc_lib/src/configure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ fn add_metadata(kind: &Kind, mut properties: Option<Map<String, Value>> ) -> Res
Ok(serde_json::to_string(&properties)?)
}

fn check_security_context(metadata: &Option<Metadata>) -> Result<(), DscError> {
fn check_security_context(metadata: Option<&Metadata>) -> Result<(), DscError> {
if metadata.is_none() {
return Ok(());
}
Expand Down Expand Up @@ -241,7 +241,7 @@ impl Configurator {
for resource in resources {
Span::current().pb_inc(1);
pb_span.pb_set_message(format!("Get '{}'", resource.name).as_str());
let properties = self.invoke_property_expressions(&resource.properties)?;
let properties = self.invoke_property_expressions(resource.properties.as_ref())?;
let Some(dsc_resource) = self.discovery.find_resource(&resource.resource_type) else {
return Err(DscError::ResourceNotFound(resource.resource_type));
};
Expand Down Expand Up @@ -299,7 +299,7 @@ impl Configurator {
for resource in resources {
Span::current().pb_inc(1);
pb_span.pb_set_message(format!("Set '{}'", resource.name).as_str());
let properties = self.invoke_property_expressions(&resource.properties)?;
let properties = self.invoke_property_expressions(resource.properties.as_ref())?;
let Some(dsc_resource) = self.discovery.find_resource(&resource.resource_type) else {
return Err(DscError::ResourceNotFound(resource.resource_type));
};
Expand Down Expand Up @@ -407,7 +407,7 @@ impl Configurator {
for resource in resources {
Span::current().pb_inc(1);
pb_span.pb_set_message(format!("Test '{}'", resource.name).as_str());
let properties = self.invoke_property_expressions(&resource.properties)?;
let properties = self.invoke_property_expressions(resource.properties.as_ref())?;
let Some(dsc_resource) = self.discovery.find_resource(&resource.resource_type) else {
return Err(DscError::ResourceNotFound(resource.resource_type));
};
Expand Down Expand Up @@ -463,7 +463,7 @@ impl Configurator {
for resource in &resources {
Span::current().pb_inc(1);
pb_span.pb_set_message(format!("Export '{}'", resource.name).as_str());
let properties = self.invoke_property_expressions(&resource.properties)?;
let properties = self.invoke_property_expressions(resource.properties.as_ref())?;
let Some(dsc_resource) = self.discovery.find_resource(&resource.resource_type) else {
return Err(DscError::ResourceNotFound(resource.resource_type.clone()));
};
Expand All @@ -488,14 +488,14 @@ impl Configurator {
/// # Errors
///
/// This function will return an error if the parameters are invalid.
pub fn set_context(&mut self, parameters_input: &Option<Value>) -> Result<(), DscError> {
pub fn set_context(&mut self, parameters_input: Option<&Value>) -> Result<(), DscError> {
let config = serde_json::from_str::<Configuration>(self.json.as_str())?;
self.set_parameters(parameters_input, &config)?;
self.set_variables(&config)?;
Ok(())
}

fn set_parameters(&mut self, parameters_input: &Option<Value>, config: &Configuration) -> Result<(), DscError> {
fn set_parameters(&mut self, parameters_input: Option<&Value>, config: &Configuration) -> Result<(), DscError> {
// set default parameters first
let Some(parameters) = &config.parameters else {
if parameters_input.is_none() {
Expand Down Expand Up @@ -636,7 +636,7 @@ impl Configurator {

fn validate_config(&mut self) -> Result<(), DscError> {
let config: Configuration = serde_json::from_str(self.json.as_str())?;
check_security_context(&config.metadata)?;
check_security_context(config.metadata.as_ref())?;

// Perform discovery of resources used in config
let required_resources = config.resources.iter().map(|p| p.resource_type.clone()).collect::<Vec<String>>();
Expand All @@ -645,7 +645,7 @@ impl Configurator {
Ok(())
}

fn invoke_property_expressions(&mut self, properties: &Option<Map<String, Value>>) -> Result<Option<Map<String, Value>>, DscError> {
fn invoke_property_expressions(&mut self, properties: Option<&Map<String, Value>>) -> Result<Option<Map<String, Value>>, DscError> {
debug!("Invoke property expressions");
if properties.is_none() {
return Ok(None);
Expand All @@ -657,7 +657,7 @@ impl Configurator {
trace!("Invoke property expression for {name}: {value}");
match value {
Value::Object(object) => {
let value = self.invoke_property_expressions(&Some(object.clone()))?;
let value = self.invoke_property_expressions(Some(&object.clone()))?;
result.insert(name.clone(), serde_json::to_value(value)?);
continue;
},
Expand All @@ -666,7 +666,7 @@ impl Configurator {
for element in array {
match element {
Value::Object(object) => {
let value = self.invoke_property_expressions(&Some(object.clone()))?;
let value = self.invoke_property_expressions(Some(&object.clone()))?;
result_array.push(serde_json::to_value(value)?);
continue;
},
Expand Down
2 changes: 1 addition & 1 deletion dsc_lib/src/discovery/command_discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl ResourceDiscovery for CommandDiscovery {
let mut adapter_resources_count = 0;
// invoke the list command
let list_command = manifest.adapter.unwrap().list;
let (exit_code, stdout, stderr) = match invoke_command(&list_command.executable, list_command.args, None, Some(&adapter.directory), None, &manifest.exit_codes)
let (exit_code, stdout, stderr) = match invoke_command(&list_command.executable, list_command.args, None, Some(&adapter.directory), None, manifest.exit_codes.as_ref())
{
Ok((exit_code, stdout, stderr)) => (exit_code, stdout, stderr),
Err(e) => {
Expand Down
Loading

0 comments on commit 3d15939

Please sign in to comment.