Skip to content

Commit

Permalink
Merge pull request #51 from elmiko/clippy-fixes
Browse files Browse the repository at this point in the history
clippy based cleanups
  • Loading branch information
elmiko authored May 11, 2024
2 parents e8ede62 + cf71203 commit f8fbf9e
Show file tree
Hide file tree
Showing 14 changed files with 2,610 additions and 38 deletions.
2,577 changes: 2,577 additions & 0 deletions camgi.html

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn add_accordion_section(
.attr(format!("data-bs-target=\"#collapse-{}\"", &resuuid.hyphenated()).as_str())
.attr("aria-exapnded=\"false\"")
.attr(format!("aria-controls=\"collapse-{}\"", &resuuid.hyphenated()).as_str())
.write_str(&res.name())?;
.write_str(res.name())?;
itemdiv
.div()
.attr(format!("id=\"collapse-{}\"", &resuuid.hyphenated()).as_str())
Expand All @@ -72,7 +72,7 @@ fn add_accordion_section(
.div()
.attr("class=\"accordion-body fs-6\"")
.pre()
.write_str(&res.raw())?;
.write_str(res.raw())?;
}

Ok(())
Expand Down Expand Up @@ -164,13 +164,13 @@ fn add_body(parent: &mut Node, mustgather: &MustGather) -> Result<()> {
// add data sections
// data sections are used by the nav list and vue app to change the content
// in the div#main-content element.
add_summary_data(&mut body, &mustgather)?;
add_summary_data(&mut body, mustgather)?;
add_resource_data(&mut body, "Cluster Operators", &mustgather.clusteroperators)?;
add_machine_api_data(&mut body, &mustgather)?;
add_machine_config_data(&mut body, &mustgather)?;
add_ccmo_data(&mut body, &mustgather)?;
add_ccms_data(&mut body, &mustgather)?;
add_autoscaling_data(&mut body, &mustgather)?;
add_machine_api_data(&mut body, mustgather)?;
add_machine_config_data(&mut body, mustgather)?;
add_ccmo_data(&mut body, mustgather)?;
add_ccms_data(&mut body, mustgather)?;
add_autoscaling_data(&mut body, mustgather)?;
add_resource_data(&mut body, "MachineSets", &mustgather.machinesets)?;
add_resource_data(&mut body, "Machines", &mustgather.machines)?;
add_resource_data(&mut body, "Nodes", &mustgather.nodes)?;
Expand Down Expand Up @@ -247,7 +247,7 @@ fn add_machine_config_data(parent: &mut Node, mustgather: &MustGather) -> Result
Ok(())
}

fn add_navlist_entry(parent: &mut Node, title: &str, resources: &Vec<impl Resource>) -> Result<()> {
fn add_navlist_entry(parent: &mut Node, title: &str, resources: &[impl Resource]) -> Result<()> {
let mut aclass = "class=\"list-group-item list-group-item-action\"";
let mut clickattr = format!(
"v-on:click=\"changeContent('{}')\"",
Expand Down Expand Up @@ -305,7 +305,7 @@ fn add_pod_accordions(parent: &mut Node, pods: &Vec<Pod>) -> Result<()> {
.attr(format!("data-bs-target=\"#collapse-{}\"", &poduuid.hyphenated()).as_str())
.attr("aria-exapnded=\"false\"")
.attr(format!("aria-controls=\"collapse-{}\"", &poduuid.hyphenated()).as_str())
.write_str(&pod.name())?;
.write_str(pod.name())?;
itemdiv
.div()
.attr(format!("id=\"collapse-{}\"", &poduuid.hyphenated()).as_str())
Expand All @@ -315,7 +315,7 @@ fn add_pod_accordions(parent: &mut Node, pods: &Vec<Pod>) -> Result<()> {
.div()
.attr("class=\"accordion-body fs-6\"")
.pre()
.write_str(&pod.raw())?;
.write_str(pod.raw())?;
for container in &pod.containers {
let containeruuid = Uuid::new_v4();
let mut itemdiv = div.div().attr("class=\"accordion-item\"");
Expand Down Expand Up @@ -379,7 +379,7 @@ fn add_resource_data(parent: &mut Node, kind: &str, resources: &Vec<impl Resourc
let mut data = parent
.data()
.attr(format!("id=\"{}-data\"", kind.replace(' ', "_").to_lowercase()).as_str());
add_accordion_section(&mut data, &kind, &resources)
add_accordion_section(&mut data, kind, resources)
}

fn add_summary_data(parent: &mut Node, mustgather: &MustGather) -> Result<()> {
Expand All @@ -401,9 +401,9 @@ fn add_summary_data(parent: &mut Node, mustgather: &MustGather) -> Result<()> {
],
)?;

add_summary_data_machinesets_section(&mut dl, &mustgather)?;
add_summary_data_machines_section(&mut dl, &mustgather)?;
add_summary_data_nodes_section(&mut dl, &mustgather)?;
add_summary_data_machinesets_section(&mut dl, mustgather)?;
add_summary_data_machines_section(&mut dl, mustgather)?;
add_summary_data_nodes_section(&mut dl, mustgather)?;

Ok(())
}
Expand Down Expand Up @@ -515,7 +515,7 @@ fn add_table(parent: &mut Node, head: Vec<&str>, body: Vec<Vec<&str>>) -> Result

let mut tbody = table.tbody();

for (_i, item) in body.iter().enumerate() {
for item in body.iter() {
let mut tr = tbody.tr();
for (ii, iitem) in item.iter().enumerate() {
let t = if ii == 0 { tr.th() } else { tr.td() };
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn main() -> Result<()> {
return Err(error);
}
};
mg = MustGather::from(tmp_dir.path().to_str().unwrap().to_owned())?;
mg = MustGather::from(tmp_dir.path().to_str().unwrap())?;
} else {
mg = MustGather::from(cli.path)?;
}
Expand Down
8 changes: 4 additions & 4 deletions src/mustgather.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ fn get_pod(pod_dir: &PathBuf) -> Option<Pod> {
}
}

if let Ok(container_dirs) = fs::read_dir(&pod_dir) {
if let Ok(container_dirs) = fs::read_dir(pod_dir) {
// loop through container dirs
for container_dir in container_dirs {
let container_dir = container_dir.ok()?.path();
Expand All @@ -288,7 +288,7 @@ fn get_pod(pod_dir: &PathBuf) -> Option<Pod> {
None => continue,
};
let mut current_log_filename = container_dir.clone();
current_log_filename.push(&container_name);
current_log_filename.push(container_name);
current_log_filename.push("logs");
current_log_filename.push("current.log");
if current_log_filename.exists() {
Expand Down Expand Up @@ -332,7 +332,7 @@ fn get_pods(path: &Path) -> Vec<Pod> {
let mut pods = Vec::new();

// each pod has a subdirectory with its name
let pod_dirs = match fs::read_dir(&path) {
let pod_dirs = match fs::read_dir(path) {
Ok(entries) => entries,
Err(_) => return pods,
};
Expand All @@ -358,7 +358,7 @@ fn get_pods(path: &Path) -> Vec<Pod> {
/// If the resource path does not exist, will return an empty list.
fn get_resources<T: Resource>(path: &Path) -> Vec<T> {
let mut resources = Vec::new();
let files = match fs::read_dir(&path) {
let files = match fs::read_dir(path) {
Ok(p) => p,
Err(_) => return resources,
};
Expand Down
2 changes: 1 addition & 1 deletion src/resources/baremetalhost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ impl Resource for BareMetalHost {
}

fn raw(&self) -> &String {
&self.manifest.as_raw()
self.manifest.as_raw()
}
}
2 changes: 1 addition & 1 deletion src/resources/certificatesigningrequest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Resource for CertificateSigningRequest {
}

fn raw(&self) -> &String {
&self.manifest.as_raw()
self.manifest.as_raw()
}

fn is_error(&self) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion src/resources/clusterautoscaler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ impl Resource for ClusterAutoscaler {
}

fn raw(&self) -> &String {
&self.manifest.as_raw()
self.manifest.as_raw()
}
}
2 changes: 1 addition & 1 deletion src/resources/clusteroperator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ impl Resource for ClusterOperator {
}

fn raw(&self) -> &String {
&self.manifest.as_raw()
self.manifest.as_raw()
}
}
2 changes: 1 addition & 1 deletion src/resources/controlplanemachineset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ impl Resource for ControlPlaneMachineSet {
}

fn raw(&self) -> &String {
&self.manifest.as_raw()
self.manifest.as_raw()
}
}
2 changes: 1 addition & 1 deletion src/resources/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Resource for Machine {
}

fn raw(&self) -> &String {
&self.manifest.as_raw()
self.manifest.as_raw()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/resources/machineautoscaler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ impl Resource for MachineAutoscaler {
}

fn raw(&self) -> &String {
&self.manifest.as_raw()
self.manifest.as_raw()
}
}
11 changes: 3 additions & 8 deletions src/resources/machineset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,17 @@ impl Resource for MachineSet {
}

fn raw(&self) -> &String {
&self.manifest.as_raw()
self.manifest.as_raw()
}
}

fn has_autoscaling_annotations(manifest: &Manifest) -> bool {
if manifest.as_yaml()["metadata"]["annotations"]
!(manifest.as_yaml()["metadata"]["annotations"]
["machine.openshift.io/cluster-api-autoscaler-node-group-min-size"]
.is_badvalue()
&& manifest.as_yaml()["metadata"]["annotations"]
["machine.openshift.io/cluster-api-autoscaler-node-group-max-size"]
.is_badvalue()
{
false
} else {
true
}
.is_badvalue())
}

fn status_replicas(manifest: &Manifest) -> String {
Expand Down
2 changes: 1 addition & 1 deletion src/resources/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ impl Resource for Node {
}

fn raw(&self) -> &String {
&self.manifest.as_raw()
self.manifest.as_raw()
}
}
2 changes: 1 addition & 1 deletion src/resources/pod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Resource for Pod {
}

fn raw(&self) -> &String {
&self.manifest.as_raw()
self.manifest.as_raw()
}
}

Expand Down

0 comments on commit f8fbf9e

Please sign in to comment.