mirror of
https://github.com/orhun/systeroid
synced 2024-10-06 15:49:09 +00:00
fix(lint): apply clippy suggestions
This commit is contained in:
parent
92ef3ec2ca
commit
7ad12c455f
|
@ -187,7 +187,7 @@ impl Sysctl {
|
|||
let save_path = save_path
|
||||
.clone()
|
||||
.unwrap_or_else(|| PathBuf::from(DEFAULT_PRELOAD));
|
||||
let data = format!("{} = {}", param_name, new_value);
|
||||
let data = format!("{param_name} = {new_value}");
|
||||
if save_path.exists() {
|
||||
let contents = reader::read_to_string(&save_path)?;
|
||||
let mut lines = contents.split('\n').collect::<Vec<&str>>();
|
||||
|
|
|
@ -36,7 +36,7 @@ impl<'a> TryFrom<&'a Ctl> for Parameter {
|
|||
description: ctl
|
||||
.description()
|
||||
.ok()
|
||||
.and_then(|v| (v == "[N/A]").then(|| None)?),
|
||||
.and_then(|v| (v == "[N/A]").then_some(None)?),
|
||||
section: Section::from_name(ctl.name()?),
|
||||
docs_path: PathBuf::new(),
|
||||
docs_title: String::new(),
|
||||
|
@ -174,7 +174,7 @@ impl Parameter {
|
|||
/// Prints the description of the kernel parameter to the given output.
|
||||
pub fn display_documentation<Output: Write>(&self, output: &mut Output) -> Result<()> {
|
||||
if let Some(documentation) = self.get_documentation() {
|
||||
writeln!(output, "{}\n", documentation)?;
|
||||
writeln!(output, "{documentation}\n")?;
|
||||
} else {
|
||||
writeln!(output, "No documentation available for {}", self.name)?;
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ impl Parameter {
|
|||
return true;
|
||||
}
|
||||
if components.peek().is_some() {
|
||||
subsection = format!("{}.{}", subsection, component)
|
||||
subsection = format!("{subsection}.{component}")
|
||||
}
|
||||
}
|
||||
false
|
||||
|
|
|
@ -27,7 +27,7 @@ impl Section {
|
|||
/// Returns the section of the given parameter name.
|
||||
pub fn from_name(name: String) -> Self {
|
||||
for section in Self::variants() {
|
||||
if name.starts_with(&format!("{}.", section)) {
|
||||
if name.starts_with(&format!("{section}.")) {
|
||||
return *section;
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ impl<'a> From<&'a Path> for Section {
|
|||
|
||||
impl Display for Section {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
write!(f, "{}", format!("{:?}", self).to_lowercase())
|
||||
write!(f, "{}", format!("{self:?}").to_lowercase())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -323,10 +323,10 @@ impl<'a> App<'a> {
|
|||
&self.sysctl.config.tui.save_path,
|
||||
) {
|
||||
Ok(path) => {
|
||||
self.input = Some(format!("Saved to file: {:?}", path));
|
||||
self.input = Some(format!("Saved to file: {path:?}"));
|
||||
}
|
||||
Err(e) => {
|
||||
self.input = Some(format!("Failed to save: {}", e));
|
||||
self.input = Some(format!("Failed to save: {e}"));
|
||||
}
|
||||
}
|
||||
self.input_time = Some(Instant::now());
|
||||
|
|
|
@ -98,7 +98,7 @@ impl Args {
|
|||
let opts = Self::get_options();
|
||||
let matches = opts
|
||||
.parse(&env_args[1..])
|
||||
.map_err(|e| eprintln!("error: `{}`", e))
|
||||
.map_err(|e| eprintln!("error: `{e}`"))
|
||||
.ok()?;
|
||||
if matches.opt_present("h") {
|
||||
let usage = opts.usage_with_format(|opts| {
|
||||
|
@ -106,7 +106,7 @@ impl Args {
|
|||
.replace("{bin}", env!("CARGO_PKG_NAME"))
|
||||
.replace("{usage}", &opts.collect::<Vec<String>>().join("\n"))
|
||||
});
|
||||
println!("{}", usage);
|
||||
println!("{usage}");
|
||||
None
|
||||
} else if matches.opt_present("V") {
|
||||
println!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
|
||||
|
@ -115,7 +115,7 @@ impl Args {
|
|||
Some(Args {
|
||||
tick_rate: matches
|
||||
.opt_get("t")
|
||||
.map_err(|e| eprintln!("error: `{}`", e))
|
||||
.map_err(|e| eprintln!("error: `{e}`"))
|
||||
.ok()?
|
||||
.unwrap_or(250),
|
||||
kernel_docs: matches
|
||||
|
|
|
@ -18,7 +18,7 @@ fn main() -> Result<()> {
|
|||
match systeroid_tui::run(args, backend) {
|
||||
Ok(_) => process::exit(0),
|
||||
Err(e) => {
|
||||
eprintln!("{}", e);
|
||||
eprintln!("{e}");
|
||||
process::exit(1)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ impl FromStr for Color {
|
|||
"lightcyan" | "light cyan" => TuiColor::LightCyan,
|
||||
"white" => TuiColor::White,
|
||||
_ => {
|
||||
let rgb = Rgb::from_hex_str(&format!("#{}", s))?;
|
||||
let rgb = Rgb::from_hex_str(&format!("#{s}"))?;
|
||||
TuiColor::Rgb(rgb.red() as u8, rgb.green() as u8, rgb.blue() as u8)
|
||||
}
|
||||
},
|
||||
|
|
|
@ -185,7 +185,7 @@ fn render_section_text<B: Backend>(
|
|||
section: &str,
|
||||
colors: &Colors,
|
||||
) {
|
||||
let section = format!("|{}|", section);
|
||||
let section = format!("|{section}|");
|
||||
let text_width: u16 = section.width().try_into().unwrap_or(1);
|
||||
let vertical_area = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
|
@ -423,7 +423,7 @@ fn render_input_prompt<B: Backend>(
|
|||
let text = match app.input.clone() {
|
||||
Some(mut input) => {
|
||||
if app.input_time.is_some() {
|
||||
format!("MSG: {}", input)
|
||||
format!("MSG: {input}")
|
||||
} else {
|
||||
let mut skip_chars = 0;
|
||||
if let Some(width_overflow) = (input.width() as u16 + 4)
|
||||
|
|
|
@ -95,7 +95,7 @@ impl<'a, Output: Write> App<'a, Output> {
|
|||
}
|
||||
Err(e) => {
|
||||
if !pager.is_empty() {
|
||||
eprintln!("pager error: `{}`", e);
|
||||
eprintln!("pager error: `{e}`");
|
||||
}
|
||||
fallback_to_default = true;
|
||||
}
|
||||
|
@ -261,7 +261,7 @@ mod tests {
|
|||
app.process_parameter(param_name.clone(), true, false)?;
|
||||
let result = String::from_utf8_lossy(app.output);
|
||||
assert!(result.contains("\"section\":\"kernel\""));
|
||||
assert!(result.contains(&format!("\"name\":\"{}\"", param_name)));
|
||||
assert!(result.contains(&format!("\"name\":\"{param_name}\"")));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ impl Args {
|
|||
let opts = Self::get_options();
|
||||
let mut matches = opts
|
||||
.parse(&env_args[1..])
|
||||
.map_err(|e| eprintln!("error: `{}`", e))
|
||||
.map_err(|e| eprintln!("error: `{e}`"))
|
||||
.ok()?;
|
||||
|
||||
let preload_files = matches.opt_present("p") || matches.opt_present("f");
|
||||
|
@ -151,7 +151,7 @@ impl Args {
|
|||
.join("\n"),
|
||||
)
|
||||
});
|
||||
println!("{}", usage);
|
||||
println!("{usage}");
|
||||
None
|
||||
} else if matches.opt_present("V") {
|
||||
println!("{} {}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
|
||||
|
|
|
@ -17,7 +17,7 @@ fn main() {
|
|||
match command.spawn().map(|mut child| child.wait()) {
|
||||
Ok(_) => process::exit(0),
|
||||
Err(e) => {
|
||||
eprintln!("Cannot run `{}` ({})", bin, e);
|
||||
eprintln!("Cannot run `{bin}` ({e})");
|
||||
process::exit(1)
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ fn main() {
|
|||
match systeroid::run(args, &mut stdout) {
|
||||
Ok(_) => process::exit(0),
|
||||
Err(e) => {
|
||||
eprintln!("{}", e);
|
||||
eprintln!("{e}");
|
||||
process::exit(1)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue