git.delta.rocks / jrsonnet / refs/commits / 3fd84331488f

difftreelog

style fix clippy warnings

Yaroslav Bolyukin2022-09-02parent: #b0625df.patch.diff
in: trunk

3 files changed

modifiedcmds/fleet/src/cmds/info.rsdiffbeforeafterboth
before · cmds/fleet/src/cmds/info.rs
1use std::collections::BTreeSet;23use crate::host::Config;4use anyhow::{ensure, Result};5use clap::Parser;67#[derive(Parser)]8pub struct Info {9	#[clap(long)]10	json: bool,11	#[clap(subcommand)]12	cmd: InfoCmd,13}1415#[derive(Parser)]16pub enum InfoCmd {17	/// List hosts18	ListHosts {19		#[clap(long)]20		tagged: Vec<String>,21	},22	/// List ips23	HostIps {24		host: String,25		#[clap(long)]26		external: bool,27		#[clap(long)]28		internal: bool,29	},30}3132impl Info {33	pub async fn run(self, config: &Config) -> Result<()> {34		let mut data = Vec::new();35		match self.cmd {36			InfoCmd::ListHosts { ref tagged } => {37				'host: for host in config.list_hosts().await? {38					if !tagged.is_empty() {39						let tags: Vec<String> = config.config_attr(&host, "tags").await?;40						for tag in tagged {41							if !tags.contains(&tag) {42								continue 'host;43							}44						}45					}46					data.push(host);47				}48			}49			InfoCmd::HostIps {50				host,51				external,52				internal,53			} => {54				ensure!(55					external || internal,56					"at leas one of --external or --internal must be set"57				);58				let mut out = <BTreeSet<String>>::new();59				if external {60					out.extend(61						config62							.config_attr::<Vec<String>>(&host, "network.externalIps")63							.await?,64					);65				}66				if internal {67					out.extend(68						config69							.config_attr::<Vec<String>>(&host, "network.internalIps")70							.await?,71					);72				}73				for ip in out {74					data.push(ip);75				}76			}77		}7879		if self.json {80			let v = serde_json::to_string_pretty(&data)?;81			print!("{}", v);82		} else {83			for v in data {84				println!("{}", v);85			}86		}87		Ok(())88	}89}
after · cmds/fleet/src/cmds/info.rs
1use std::collections::BTreeSet;23use crate::host::Config;4use anyhow::{ensure, Result};5use clap::Parser;67#[derive(Parser)]8pub struct Info {9	#[clap(long)]10	json: bool,11	#[clap(subcommand)]12	cmd: InfoCmd,13}1415#[derive(Parser)]16pub enum InfoCmd {17	/// List hosts18	ListHosts {19		#[clap(long)]20		tagged: Vec<String>,21	},22	/// List ips23	HostIps {24		host: String,25		#[clap(long)]26		external: bool,27		#[clap(long)]28		internal: bool,29	},30}3132impl Info {33	pub async fn run(self, config: &Config) -> Result<()> {34		let mut data = Vec::new();35		match self.cmd {36			InfoCmd::ListHosts { ref tagged } => {37				'host: for host in config.list_hosts().await? {38					if !tagged.is_empty() {39						let tags: Vec<String> = config.config_attr(&host, "tags").await?;40						for tag in tagged {41							if !tags.contains(tag) {42								continue 'host;43							}44						}45					}46					data.push(host);47				}48			}49			InfoCmd::HostIps {50				host,51				external,52				internal,53			} => {54				ensure!(55					external || internal,56					"at leas one of --external or --internal must be set"57				);58				let mut out = <BTreeSet<String>>::new();59				if external {60					out.extend(61						config62							.config_attr::<Vec<String>>(&host, "network.externalIps")63							.await?,64					);65				}66				if internal {67					out.extend(68						config69							.config_attr::<Vec<String>>(&host, "network.internalIps")70							.await?,71					);72				}73				for ip in out {74					data.push(ip);75				}76			}77		}7879		if self.json {80			let v = serde_json::to_string_pretty(&data)?;81			print!("{}", v);82		} else {83			for v in data {84				println!("{}", v);85			}86		}87		Ok(())88	}89}
modifiedcmds/fleet/src/keys.rsdiffbeforeafterboth
--- a/cmds/fleet/src/keys.rs
+++ b/cmds/fleet/src/keys.rs
@@ -50,7 +50,7 @@
 			.filter(|(_, host)| !host.encryption_key.is_empty())
 			.map(|(n, _)| n)
 		{
-			if !host_names.contains(&hostname.to_owned()) {
+			if !host_names.contains(hostname) {
 				out.push(hostname.to_owned())
 			}
 		}
modifiedcrates/nixlike/src/to_string.rsdiffbeforeafterboth
--- a/crates/nixlike/src/to_string.rs
+++ b/crates/nixlike/src/to_string.rs
@@ -5,7 +5,7 @@
 };
 
 fn write_nix_obj_key_buf(k: &str, v: &Value, out: &mut PrintItems) {
-	if k.contains(".") {
+	if k.contains('.') {
 		out.push_str("\"");
 		out.push_str(k);
 		out.push_str("\"");
@@ -39,7 +39,7 @@
 				.replace('\n', "\\n")
 				.replace('\t', "\\t")
 				.replace('\r', "\\r")
-				.replace("$", "\\$")
+				.replace('$', "\\$")
 		)),
 		Value::Array(a) => {
 			if a.is_empty() {