Skip to content

Commit

Permalink
fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkjall committed Dec 30, 2024
1 parent 2fe1008 commit b9586cf
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 191 deletions.
2 changes: 1 addition & 1 deletion cursive/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn set_clipboard(content: &String) -> Result<()> {
Ok(CLIPBOARD.lock().unwrap().set_text(content)?)
}

pub fn get_value_from_input(s: &mut Cursive, input_name: &str) -> Option<std::sync::Arc<String>> {
pub fn get_value_from_input(s: &mut Cursive, input_name: &str) -> Option<Arc<String>> {
let mut password = None;
s.call_on_name(input_name, |e: &mut EditView| {
password = Some(e.get_content());
Expand Down
71 changes: 30 additions & 41 deletions cursive/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fn up(ui: &mut Cursive) {
}

fn page_down(ui: &mut Cursive) {
let rows = screen_height(&ui) - 7;
let rows = screen_height(ui) - 7;
ui.call_on_name("results", |l: &mut SelectView<pass::PasswordEntry>| {
l.select_down(rows);
});
Expand All @@ -119,7 +119,7 @@ fn page_down(ui: &mut Cursive) {
}

fn page_up(ui: &mut Cursive) {
let rows = screen_height(&ui) - 7;
let rows = screen_height(ui) - 7;
ui.call_on_name("results", |l: &mut SelectView<pass::PasswordEntry>| {
l.select_up(rows);
});
Expand All @@ -140,7 +140,7 @@ fn copy(ui: &mut Cursive, store: PasswordStoreType) {
if sel.is_none() {
return;
}
if let Err(err) = || -> pass::Result<()> {
if let Err(err) = || -> Result<()> {
let mut secret: String = sel.unwrap().secret(&*store.lock()?.lock()?)?;
helpers::set_clipboard(&secret)?;
secret.zeroize();
Expand Down Expand Up @@ -168,7 +168,7 @@ fn copy_first_line(ui: &mut Cursive, store: PasswordStoreType) {
if sel.is_none() {
return;
}
if let Err(err) = || -> pass::Result<()> {
if let Err(err) = || -> Result<()> {
let mut secret = sel.unwrap().password(&*store.lock()?.lock()?)?;
helpers::set_clipboard(&secret)?;
secret.zeroize();
Expand Down Expand Up @@ -198,7 +198,7 @@ fn copy_mfa(ui: &mut Cursive, store: PasswordStoreType) {
if sel.is_none() {
return;
}
if let Err(err) = || -> pass::Result<()> {
if let Err(err) = || -> Result<()> {
let mut secret = sel.unwrap().mfa(&*store.lock()?.lock()?)?;
helpers::set_clipboard(&secret)?;
secret.zeroize();
Expand All @@ -224,7 +224,7 @@ fn copy_name(ui: &mut Cursive) {
}
let sel = sel.unwrap();

if let Err(err) = || -> pass::Result<()> {
if let Err(err) = || -> Result<()> {
let name = sel.name.split('/').next_back();
helpers::set_clipboard(&name.unwrap_or("").to_string())?;
Ok(())
Expand Down Expand Up @@ -281,8 +281,8 @@ fn delete(ui: &mut Cursive, store: PasswordStoreType) {
));
}

fn get_selected_password_entry(ui: &mut Cursive) -> Option<ripasso::pass::PasswordEntry> {
let password_entry_option: Option<Option<Arc<ripasso::pass::PasswordEntry>>> = ui
fn get_selected_password_entry(ui: &mut Cursive) -> Option<pass::PasswordEntry> {
let password_entry_option: Option<Option<Arc<pass::PasswordEntry>>> = ui
.call_on_name("results", |l: &mut SelectView<pass::PasswordEntry>| {
l.selection()
});
Expand Down Expand Up @@ -716,12 +716,12 @@ fn create(ui: &mut Cursive, store: PasswordStoreType) {

fn delete_recipient(ui: &mut Cursive, store: PasswordStoreType) -> Result<()> {
let mut l = ui
.find_name::<SelectView<Option<(PathBuf, pass::Recipient)>>>("recipients")
.find_name::<SelectView<Option<(PathBuf, Recipient)>>>("recipients")
.unwrap();
let sel = l.selection();

if sel.is_none() || sel.as_ref().unwrap().is_none() {
return Err(crate::pass::Error::Generic("Selection is empty"));
return Err(pass::Error::Generic("Selection is empty"));
}

let binding = sel.unwrap();
Expand Down Expand Up @@ -795,9 +795,7 @@ fn add_recipient(ui: &mut Cursive, store: PasswordStoreType, config_path: &Path)
}

let mut recipients_view = ui
.find_name::<SelectView<Option<(PathBuf, pass::Recipient)>>>(
"recipients",
)
.find_name::<SelectView<Option<(PathBuf, Recipient)>>>("recipients")
.unwrap();
recipients_view.add_item(
render_recipient_label(&recipient, max_width_key, max_width_name),
Expand Down Expand Up @@ -870,7 +868,7 @@ fn add_recipient_dialog(ui: &mut Cursive, store: PasswordStoreType, config_path:
}

fn render_recipient_label(
recipient: &pass::Recipient,
recipient: &Recipient,
max_width_key: usize,
max_width_name: usize,
) -> String {
Expand Down Expand Up @@ -929,7 +927,7 @@ fn view_recipients(ui: &mut Cursive, store: PasswordStoreType, config_path: &Pat
helpers::errorbox(ui, &err);
return Ok(());
}
let sub_dirs = sub_dirs.unwrap();
let sub_dirs = sub_dirs?;

match sub_dirs.len().cmp(&1) {
std::cmp::Ordering::Greater => {
Expand All @@ -942,7 +940,7 @@ fn view_recipients(ui: &mut Cursive, store: PasswordStoreType, config_path: &Pat
return Ok(());
}

path_to_recipients.insert(dir.clone(), recipients_res.unwrap());
path_to_recipients.insert(dir.clone(), recipients_res?);
}

view_recipients_for_many_dirs(ui, store, path_to_recipients, config_path);
Expand Down Expand Up @@ -971,7 +969,7 @@ fn view_recipients_for_many_dirs(
path_to_recipients: HashMap<PathBuf, Vec<Recipient>>,
config_path: &Path,
) {
let mut recipients_view = SelectView::<Option<(PathBuf, pass::Recipient)>>::new()
let mut recipients_view = SelectView::<Option<(PathBuf, Recipient)>>::new()
.h_align(cursive::align::HAlign::Left)
.with_name("recipients");

Expand Down Expand Up @@ -1048,9 +1046,9 @@ fn view_recipients_for_dir(
helpers::errorbox(ui, &err);
return Ok(());
}
let recipients = recipients_res.unwrap();
let recipients = recipients_res?;

let mut recipients_view = SelectView::<Option<(PathBuf, pass::Recipient)>>::new()
let mut recipients_view = SelectView::<Option<(PathBuf, Recipient)>>::new()
.h_align(cursive::align::HAlign::Left)
.with_name("recipients");

Expand Down Expand Up @@ -1108,10 +1106,7 @@ fn create_label(p: &pass::PasswordEntry, col: usize) -> String {
let committed_by = p.committed_by.clone();
let updated = p.updated;
let name = substr(
&match committed_by {
Some(d) => d,
None => CATALOG.gettext("n/a").to_string(),
},
&committed_by.unwrap_or_else(|| CATALOG.gettext("n/a").to_string()),
0,
15,
);
Expand Down Expand Up @@ -1377,12 +1372,8 @@ fn get_stores(config: &config::Config, home: &Option<PathBuf>) -> Result<Vec<Pas
let stores: HashMap<String, config::Value> = stores;

for store_name in stores.keys() {
let store: HashMap<String, config::Value> = stores
.get(store_name)
.unwrap()
.clone()
.into_table()
.unwrap();
let store: HashMap<String, config::Value> =
stores.get(store_name).unwrap().clone().into_table()?;

let password_store_dir_opt = store.get("path");
let valid_signing_keys_opt = store.get("valid_signing_keys");
Expand Down Expand Up @@ -1520,8 +1511,7 @@ fn save_edit_config(

let e_k = if e_k_bool {
let mut recipients: Vec<Recipient> = vec![];
for (i, r) in all_recipients_from_stores(stores.clone())
.unwrap()
for (i, r) in all_recipients_from_stores(stores.clone())?
.iter()
.enumerate()
{
Expand Down Expand Up @@ -1563,7 +1553,7 @@ fn save_edit_config(
helpers::errorbox(ui, &err);
return Ok(());
}
let new_store = new_store.unwrap();
let new_store = new_store?;

let l = ui.find_name::<SelectView<String>>("stores").unwrap();

Expand Down Expand Up @@ -2040,7 +2030,7 @@ fn main() -> Result<()> {
2 => {
if args[1] == "-h" || args[1] == "--help" {
help();
std::process::exit(0);
process::exit(0);
} else {
eprintln!(
"{}",
Expand Down Expand Up @@ -2092,7 +2082,7 @@ fn main() -> Result<()> {
eprintln!("Error {err}");
process::exit(1);
}
let (config, config_file_location) = config_res.unwrap();
let (config, config_file_location) = config_res?;

for path in validate_stores_config(&config, &home) {
wizard::show_init_menu(&Some(path), &home);
Expand All @@ -2105,8 +2095,7 @@ fn main() -> Result<()> {
}

let stores: StoreListType = Arc::new(Mutex::new(
stores
.unwrap()
stores?
.into_iter()
.map(|s| Arc::new(Mutex::new(s)))
.collect(),
Expand Down Expand Up @@ -2175,8 +2164,8 @@ fn main() -> Result<()> {
// Movement
ui.add_global_callback(Event::CtrlChar('n'), down);
ui.add_global_callback(Event::CtrlChar('p'), up);
ui.add_global_callback(Event::Key(cursive::event::Key::PageDown), page_down);
ui.add_global_callback(Event::Key(cursive::event::Key::PageUp), page_up);
ui.add_global_callback(Event::Key(Key::PageDown), page_down);
ui.add_global_callback(Event::Key(Key::PageUp), page_up);

// View list of persons that have access
ui.add_global_callback(Event::CtrlChar('v'), {
Expand Down Expand Up @@ -2224,14 +2213,14 @@ fn main() -> Result<()> {
do_git_push(ui, store.clone());
}
});
ui.add_global_callback(Event::Key(cursive::event::Key::Ins), {
ui.add_global_callback(Event::Key(Key::Ins), {
let store = store.clone();
move |ui: &mut Cursive| {
create(ui, store.clone());
}
});

ui.add_global_callback(Event::Key(cursive::event::Key::Esc), |s| s.quit());
ui.add_global_callback(Event::Key(Key::Esc), |s| s.quit());

if let Err(err) = ui.load_toml(&get_style(&store.lock()?.lock()?.get_style_file())) {
eprintln!("Error {err:?}");
Expand All @@ -2240,7 +2229,7 @@ fn main() -> Result<()> {
let search_box = EditView::new()
.on_edit({
let store = store.clone();
move |ui: &mut cursive::Cursive, query, _| {
move |ui: &mut Cursive, query, _| {
do_search(&store, ui, query);
}
})
Expand Down
8 changes: 4 additions & 4 deletions cursive/src/tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn is_checkbox_checked_false() {
let mut siv = cursive::default();
siv.add_layer(Checkbox::new().with_name("unit_test"));

assert_eq!(false, is_checkbox_checked(&mut siv, "unit_test"));
assert!(!is_checkbox_checked(&mut siv, "unit_test"));
}

#[test]
Expand All @@ -39,7 +39,7 @@ fn is_checkbox_checked_true() {
c_b.set_checked(true);
siv.add_layer(c_b.with_name("unit_test"));

assert_eq!(true, is_checkbox_checked(&mut siv, "unit_test"));
assert!(is_checkbox_checked(&mut siv, "unit_test"));
}

#[test]
Expand All @@ -56,7 +56,7 @@ fn is_radio_button_selected_false() {

siv.add_layer(ll);

assert_eq!(false, is_radio_button_selected(&mut siv, "button1_name"));
assert!(!is_radio_button_selected(&mut siv, "button1_name"));
}

#[test]
Expand All @@ -79,5 +79,5 @@ fn is_radio_button_selected_true() {
e.select();
});

assert_eq!(true, is_radio_button_selected(&mut siv, "button2_name"));
assert!(is_radio_button_selected(&mut siv, "button2_name"));
}
4 changes: 2 additions & 2 deletions cursive/src/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ fn do_delete_normal() {
let mut siv = cursive::default();

let td = tempdir().unwrap();
std::fs::create_dir(&td.path().join(".password-store")).unwrap();
std::fs::create_dir(td.path().join(".password-store")).unwrap();
std::fs::write(
&td.path().join(".password-store").join("file.gpg"),
td.path().join(".password-store").join("file.gpg"),
"pgp-data",
)
.unwrap();
Expand Down
5 changes: 1 addition & 4 deletions gtk/src/password_object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ impl PasswordObject {
},
};

let commit_name = match p_e.committed_by {
Some(n) => n,
None => "".into(),
};
let commit_name = p_e.committed_by.unwrap_or_else(|| "".into());

Self::new(p_e.name, p_e.path, file_date, commit_name, store)
}
Expand Down
10 changes: 3 additions & 7 deletions gtk/src/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl Window {

collection_object
.bind_property("title", &label, "label")
.flags(glib::BindingFlags::SYNC_CREATE)
.flags(BindingFlags::SYNC_CREATE)
.build();

ListBoxRow::builder().child(&label).build()
Expand Down Expand Up @@ -449,12 +449,8 @@ fn get_stores(
let stores: HashMap<String, config::Value> = stores;

for store_name in stores.keys() {
let store: HashMap<String, config::Value> = stores
.get(store_name)
.unwrap()
.clone()
.into_table()
.unwrap();
let store: HashMap<String, config::Value> =
stores.get(store_name).unwrap().clone().into_table()?;

let password_store_dir_opt = store.get("path");
let valid_signing_keys_opt = store.get("valid_signing_keys");
Expand Down
Loading

0 comments on commit b9586cf

Please sign in to comment.