chore(clippy): apply fixes automatically

Signed-off-by: simonsan <14062932+simonsan@users.noreply.github.com>
This commit is contained in:
simonsan 2024-11-20 04:22:44 +01:00
parent 99d28fa0c3
commit a0e91053c7
No known key found for this signature in database
GPG Key ID: E11D13668EC3B71B
20 changed files with 76 additions and 68 deletions

View File

@ -99,7 +99,7 @@ impl Application for RusticApp {
self.state.components_mut().after_config(&config)?;
// set all given environment variables
for (env, value) in config.global.env.iter() {
for (env, value) in &config.global.env {
env::set_var(env, value);
}

View File

@ -128,7 +128,7 @@ impl CopyCmd {
let mut table =
table_with_titles(["ID", "Time", "Host", "Label", "Tags", "Paths", "Status"]);
for CopySnapshot { relevant, sn } in snaps.iter() {
for CopySnapshot { relevant, sn } in &snaps {
let tags = sn.tags.formatln();
let paths = sn.paths.formatln();
let time = sn.time.format("%Y-%m-%d %H:%M:%S").to_string();

View File

@ -73,7 +73,7 @@ impl AddCmd {
let pass = pass_opts
.evaluate_password()
.map_err(|err| err.into())
.map_err(Into::into)
.transpose()
.unwrap_or_else(|| -> Result<_> {
Ok(Password::new()

View File

@ -116,8 +116,7 @@ impl NodeLs for Node {
},
self.meta
.mode
.map(parse_permissions)
.unwrap_or_else(|| "?????????".to_string())
.map_or_else(|| "?????????".to_string(), parse_permissions)
)
}
fn link_str(&self) -> String {
@ -201,10 +200,10 @@ pub fn print_node(node: &Node, path: &Path, numeric_uid_gid: bool) {
}
.unwrap_or_else(|| "?".to_string()),
node.meta.size,
node.meta
.mtime
.map(|t| t.format("%_d %b %Y %H:%M").to_string())
.unwrap_or_else(|| "?".to_string()),
node.meta.mtime.map_or_else(
|| "?".to_string(),
|t| t.format("%_d %b %Y %H:%M").to_string()
),
node.link_str(),
);
}

View File

@ -89,10 +89,9 @@ fn run_app<B: Backend, P: ProgressBars, S: IndexedFull>(
loop {
_ = terminal.write().unwrap().draw(|f| ui(f, &mut app))?;
let event = event::read()?;
use KeyCode::*;
if let Event::Key(KeyEvent {
code: Char('c'),
code: KeyCode::Char('c'),
modifiers: KeyModifiers::CONTROL,
kind: KeyEventKind::Press,
..

View File

@ -2,7 +2,10 @@ use std::path::{Path, PathBuf};
use anyhow::Result;
use crossterm::event::{Event, KeyCode, KeyEventKind};
use ratatui::{prelude::*, widgets::*};
use ratatui::{
prelude::*,
widgets::{Block, Borders, Paragraph},
};
use rustic_core::{
repofile::{Node, SnapshotFile, Tree},
vfs::OpenFile,
@ -35,7 +38,7 @@ enum CurrentScreen<'a, P, S> {
const INFO_TEXT: &str =
"(Esc) quit | (Enter) enter dir | (Backspace) return to parent | (v) view | (r) restore | (?) show all commands";
const HELP_TEXT: &str = r#"
const HELP_TEXT: &str = r"
General Commands:
q,Esc : exit
@ -46,7 +49,7 @@ General Commands:
n : toggle numeric IDs
? : show this help page
"#;
";
pub(crate) struct Snapshot<'a, P, S> {
current_screen: CurrentScreen<'a, P, S>,
@ -105,11 +108,10 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshot<'a, P, S> {
};
let name = node.name().to_string_lossy().to_string();
let size = node.meta.size.to_string();
let mtime = node
.meta
.mtime
.map(|t| format!("{}", t.format("%Y-%m-%d %H:%M:%S")))
.unwrap_or_else(|| "?".to_string());
let mtime = node.meta.mtime.map_or_else(
|| "?".to_string(),
|t| format!("{}", t.format("%Y-%m-%d %H:%M:%S")),
);
[name, size, node.mode_str(), user, group, mtime]
.into_iter()
.map(Text::from)
@ -188,7 +190,7 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshot<'a, P, S> {
}
pub fn input(&mut self, event: Event) -> Result<SnapshotResult> {
use KeyCode::*;
use KeyCode::{Backspace, Char, Enter, Esc, Left, Right};
match &mut self.current_screen {
CurrentScreen::Snapshot => match event {
Event::Key(key) if key.kind == KeyEventKind::Press => match key.code {
@ -271,7 +273,7 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshot<'a, P, S> {
},
CurrentScreen::ShowHelp(_) => match event {
Event::Key(key) if key.kind == KeyEventKind::Press => {
if matches!(key.code, Char('q') | Esc | Enter | Char(' ') | Char('?')) {
if matches!(key.code, Char('q' | ' ' | '?') | Esc | Enter) {
self.current_screen = CurrentScreen::Snapshot;
}
}

View File

@ -97,7 +97,7 @@ impl TuiProgress {
};
let eta = match ratio {
r if r < 0.01 => " ETA: -".to_string(),
r if r > 0.999999 => String::new(),
r if r > 0.999_999 => String::new(),
r => {
format!(
" ETA: {}",

View File

@ -35,7 +35,7 @@ pub(crate) struct Restore<'a, P, S> {
impl<'a, P: ProgressBars, S: IndexedFull> Restore<'a, P, S> {
pub fn new(repo: &'a Repository<P, S>, node: Node, source: String, path: &str) -> Self {
let opts = RestoreOptions::default();
let title = format!("restore {} to:", source);
let title = format!("restore {source} to:");
let popup = popup_input(title, "enter restore destination", path, 1);
Self {
current_screen: CurrentScreen::GetDestination(popup),
@ -87,7 +87,7 @@ impl<'a, P: ProgressBars, S: IndexedFull> Restore<'a, P, S> {
}
pub fn input(&mut self, event: Event) -> Result<bool> {
use KeyCode::*;
use KeyCode::{Char, Enter, Esc};
match &mut self.current_screen {
CurrentScreen::GetDestination(prompt) => match prompt.input(event) {
TextInputResult::Cancel => return Ok(true),
@ -139,7 +139,7 @@ Do you want to proceed (y/n)?
},
CurrentScreen::RestoreDone(_) => match event {
Event::Key(key) if key.kind == KeyEventKind::Press => {
if matches!(key.code, Char('q') | Esc | Enter | Char(' ')) {
if matches!(key.code, Char('q' | ' ') | Esc | Enter) {
return Ok(true);
}
}

View File

@ -4,7 +4,10 @@ use anyhow::Result;
use chrono::Local;
use crossterm::event::{Event, KeyCode, KeyEventKind, KeyModifiers};
use itertools::Itertools;
use ratatui::{prelude::*, widgets::*};
use ratatui::{
prelude::*,
widgets::{Block, Borders, Paragraph},
};
use rustic_core::{
repofile::{DeleteOption, SnapshotFile},
IndexedFull, ProgressBars, Repository, SnapshotGroup, SnapshotGroupCriterion, StringList,
@ -74,7 +77,7 @@ enum SnapshotNode {
const INFO_TEXT: &str =
"(Esc) quit | (F5) reload snapshots | (Enter) show contents | (v) toggle view | (i) show snapshot | (?) show all commands";
const HELP_TEXT: &str = r#"General Commands:
const HELP_TEXT: &str = r"General Commands:
q, Esc : exit
F5 : re-read all snapshots from repository
Enter : show snapshot contents
@ -105,7 +108,7 @@ const HELP_TEXT: &str = r#"General Commands:
r : remove tag(s) for snapshot(s)
p : set delete protection for snapshot(s)
Ctrl-p : remove delete protection for snapshot(s)
"#;
";
pub(crate) struct Snapshots<'a, P, S> {
current_screen: CurrentScreen<'a, P, S>,
@ -362,11 +365,11 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshots<'a, P, S> {
let paths = group
.paths
.as_ref()
.map_or_else(String::default, |p| p.formatln());
.map_or_else(String::default, StringList::formatln);
let tags = group
.tags
.as_ref()
.map_or_else(String::default, |t| t.formatln());
.map_or_else(String::default, StringList::formatln);
[
mark.to_string(),
format!("{collapse}{modified}{del}group"),
@ -437,7 +440,7 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshots<'a, P, S> {
}
pub fn clear_marks(&mut self) {
for status in self.snaps_status.iter_mut() {
for status in &mut self.snaps_status {
status.marked = false;
}
self.update_table();
@ -650,7 +653,7 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshots<'a, P, S> {
}
pub fn clear_to_forget(&mut self) {
for status in self.snaps_status.iter_mut() {
for status in &mut self.snaps_status {
status.to_forget = false;
}
self.update_table();
@ -718,7 +721,7 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshots<'a, P, S> {
}
pub fn input(&mut self, event: Event) -> Result<bool> {
use KeyCode::*;
use KeyCode::{Char, Enter, Esc, Left, Right, F};
match &mut self.current_screen {
CurrentScreen::Snapshots => {
match event {
@ -846,10 +849,7 @@ impl<'a, P: ProgressBars, S: IndexedFull> Snapshots<'a, P, S> {
}
CurrentScreen::SnapshotDetails(_) | CurrentScreen::ShowHelp(_) => match event {
Event::Key(key) if key.kind == KeyEventKind::Press => {
if matches!(
key.code,
Char('q') | Esc | Enter | Char(' ') | Char('i') | Char('?')
) {
if matches!(key.code, Char('q' | ' ' | 'i' | '?') | Esc | Enter) {
self.current_screen = CurrentScreen::Snapshots;
}
}

View File

@ -20,7 +20,10 @@ pub use with_block::*;
use crossterm::event::Event;
use crossterm::event::{KeyCode, KeyEvent, KeyEventKind};
use ratatui::prelude::*;
use ratatui::widgets::*;
use ratatui::widgets::{
Block, Clear, Gauge, Paragraph, Row, Scrollbar, ScrollbarOrientation, ScrollbarState, Table,
TableState,
};
pub trait ProcessEvent {
type Result;

View File

@ -1,4 +1,4 @@
use super::*;
use super::{Clear, Constraint, Draw, Event, Frame, Layout, ProcessEvent, Rect, SizedWidget};
// Make a popup from a SizedWidget
pub struct PopUp<T>(pub T);

View File

@ -1,4 +1,4 @@
use super::*;
use super::{Draw, Event, Frame, KeyCode, KeyEventKind, ProcessEvent, Rect, SizedWidget};
pub struct Prompt<T>(pub T);
@ -26,11 +26,11 @@ impl<T: Draw> Draw for Prompt<T> {
impl<T> ProcessEvent for Prompt<T> {
type Result = PromptResult;
fn input(&mut self, event: Event) -> PromptResult {
use KeyCode::*;
use KeyCode::{Char, Enter, Esc};
match event {
Event::Key(key) if key.kind == KeyEventKind::Press => match key.code {
Char('q') | Char('n') | Char('c') | Esc => PromptResult::Cancel,
Enter | Char('y') | Char('j') | Char(' ') => PromptResult::Ok,
Char('q' | 'n' | 'c') | Esc => PromptResult::Cancel,
Enter | Char('y' | 'j' | ' ') => PromptResult::Ok,
_ => PromptResult::None,
},
_ => PromptResult::None,

View File

@ -1,4 +1,8 @@
use super::*;
use super::{
layout, style, Color, Constraint, Draw, Event, Frame, KeyCode, KeyEventKind, Layout, Modifier,
ProcessEvent, Rect, Row, Scrollbar, ScrollbarOrientation, ScrollbarState, SizedWidget, Style,
Stylize, Table, TableState, Text,
};
use std::iter::once;
use style::palette::tailwind;
@ -67,7 +71,7 @@ impl SelectTable {
row.iter()
.zip(widths.iter())
.map(|(r, w)| r.max(w))
.cloned()
.copied()
.collect()
})
.unwrap_or_default();
@ -161,7 +165,7 @@ impl SelectTable {
impl ProcessEvent for SelectTable {
type Result = ();
fn input(&mut self, event: Event) {
use KeyCode::*;
use KeyCode::{Down, End, Home, PageDown, PageUp, Up};
match event {
Event::Key(key) if key.kind == KeyEventKind::Press => match key.code {
Down => self.next(),

View File

@ -1,4 +1,4 @@
use super::*;
use super::{Color, Draw, Frame, Gauge, Rect, SizedWidget, Span, Style};
pub struct SizedGauge {
p: Gauge<'static>,

View File

@ -1,4 +1,4 @@
use super::*;
use super::{Draw, Frame, Paragraph, Rect, SizedWidget, Text};
pub struct SizedParagraph {
p: Paragraph<'static>,

View File

@ -1,4 +1,4 @@
use super::*;
use super::{Constraint, Draw, Frame, Rect, Row, SizedWidget, Table, Text};
pub struct SizedTable {
table: Table<'static>,
@ -20,14 +20,14 @@ impl SizedTable {
row.iter()
.zip(widths.iter())
.map(|(r, w)| r.max(w))
.cloned()
.copied()
.collect()
})
.unwrap_or_default();
let width = widths
.iter()
.cloned()
.copied()
.reduce(|width, w| width + w + 1) // +1 because of space between entries
.unwrap_or_default();

View File

@ -1,4 +1,4 @@
use super::*;
use super::{Draw, Event, Frame, KeyCode, KeyEvent, ProcessEvent, Rect, SizedWidget, Style};
use crossterm::event::KeyModifiers;
use tui_textarea::{CursorMove, TextArea};
@ -53,14 +53,13 @@ impl ProcessEvent for TextInput {
let KeyEvent {
code, modifiers, ..
} = key;
use KeyCode::*;
if self.changeable {
match (code, modifiers) {
(Esc, _) => return TextInputResult::Cancel,
(Enter, _) if self.lines == 1 => {
(KeyCode::Esc, _) => return TextInputResult::Cancel,
(KeyCode::Enter, _) if self.lines == 1 => {
return TextInputResult::Input(self.textarea.lines().join("\n"));
}
(Char('s'), KeyModifiers::CONTROL) => {
(KeyCode::Char('s'), KeyModifiers::CONTROL) => {
return TextInputResult::Input(self.textarea.lines().join("\n"));
}
_ => {
@ -69,14 +68,16 @@ impl ProcessEvent for TextInput {
}
} else {
match (code, modifiers) {
(Esc | Enter | Char('q') | Char('x'), _) => return TextInputResult::Cancel,
(Home, _) => {
(KeyCode::Esc | KeyCode::Enter | KeyCode::Char('q' | 'x'), _) => {
return TextInputResult::Cancel
}
(KeyCode::Home, _) => {
self.textarea.move_cursor(CursorMove::Top);
}
(End, _) => {
(KeyCode::End, _) => {
self.textarea.move_cursor(CursorMove::Bottom);
}
(PageDown | PageUp | Up | Down, _) => {
(KeyCode::PageDown | KeyCode::PageUp | KeyCode::Up | KeyCode::Down, _) => {
_ = self.textarea.input(key);
}
_ => {}

View File

@ -1,4 +1,4 @@
use super::*;
use super::{layout, Block, Draw, Event, Frame, ProcessEvent, Rect, SizedWidget};
use layout::Size;
pub struct WithBlock<T> {

View File

@ -80,9 +80,9 @@ impl Hooks {
/// or error depending on the `on_failure` setting.
pub fn use_with<T>(&self, f: impl FnOnce() -> Result<T>) -> Result<T> {
match self.run_before() {
Ok(_) => match f() {
Ok(()) => match f() {
Ok(result) => match self.run_after() {
Ok(_) => {
Ok(()) => {
self.run_finally()?;
Ok(result)
}

View File

@ -16,11 +16,11 @@ Application based on the [Abscissa] framework.
unused_lifetimes,
unused_qualifications,
// TODO: Activate if you're feeling like fixing stuff
// clippy::pedantic,
// clippy::correctness,
// clippy::suspicious,
// clippy::complexity,
// clippy::perf,
clippy::pedantic,
clippy::correctness,
clippy::suspicious,
clippy::complexity,
clippy::perf,
clippy::nursery,
bad_style,
dead_code,