From f2c9ce5fa0d75bfe3b8d1376dc3eefdf1397bc19 Mon Sep 17 00:00:00 2001 From: FliegendeWurst <2012gdwu+github@posteo.de> Date: Fri, 21 Oct 2022 09:47:16 +0200 Subject: [PATCH] Apply rustfmt --- src/cli.rs | 41 ++++++++++++++++++------------------ src/ilias.rs | 8 ++++--- src/ilias/folder.rs | 6 ++---- src/ilias/plugin_dispatch.rs | 4 +++- src/main.rs | 7 +++--- 5 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 196a079..fa2c9ad 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -174,35 +174,34 @@ pub fn ask_user_pass(opt: &Opt) -> Result<(String, String)> { error!(e); pass = rpassword::prompt_password("Password: ").context("password prompt")?; should_store = true; - } + }, } } else if let Some(pass_path) = &opt.pass_path { - let pw_out = Command::new("pass") - .arg("show") - .arg(pass_path) - .output() - .map_err(|x| { - if x.kind() == ErrorKind::NotFound { - Error::new(ErrorKind::NotFound, "pass not found in $PATH!") - } else { - x - } - })?; + let pw_out = Command::new("pass").arg("show").arg(pass_path).output().map_err(|x| { + if x.kind() == ErrorKind::NotFound { + Error::new(ErrorKind::NotFound, "pass not found in $PATH!") + } else { + x + } + })?; if !pw_out.status.success() { return Err(Error::new( ErrorKind::Other, format!( "`pass` failed with non-zero exit code {}: {}", - pw_out.status.code() - .expect("Failed retrieving pass exit code!"), - String::from_utf8(pw_out.stderr) - .expect("Failed decoding stderr of pass!") - ) - ))? + pw_out.status.code().expect("Failed retrieving pass exit code!"), + String::from_utf8(pw_out.stderr).expect("Failed decoding stderr of pass!") + ), + ))?; } else { - pass = String::from_utf8(pw_out.stdout).map(|x| { - x.lines().next().map(|x| x.to_owned()).ok_or_else(|| anyhow!("empty pass(1) entry!")) - })?.expect("utf-8 decode of `pass(1)`-output failed"); + pass = String::from_utf8(pw_out.stdout) + .map(|x| { + x.lines() + .next() + .map(|x| x.to_owned()) + .ok_or_else(|| anyhow!("empty pass(1) entry")) + })? + .expect("utf-8 decode of `pass(1)`-output failed"); should_store = false; } } else { diff --git a/src/ilias.rs b/src/ilias.rs index 049184c..eaad6a0 100644 --- a/src/ilias.rs +++ b/src/ilias.rs @@ -28,8 +28,10 @@ static ALERT_DANGER: Lazy = Lazy::new(|| Selector::parse("div.alert-da static IL_CONTENT_CONTAINER: Lazy = Lazy::new(|| Selector::parse("#il_center_col").unwrap()); static BLOCK_FAVORITES: Lazy = Lazy::new(|| Selector::parse("#block_pditems_0").unwrap()); static ITEM_PROP: Lazy = Lazy::new(|| Selector::parse("span.il_ItemProperty").unwrap()); -static CONTAINER_ITEMS: Lazy = Lazy::new(|| Selector::parse("div.il_ContainerListItem, .il-std-item").unwrap()); -static CONTAINER_ITEM_TITLE: Lazy = Lazy::new(|| Selector::parse("a.il_ContainerItemTitle, .il-item-title > a").unwrap()); +static CONTAINER_ITEMS: Lazy = + Lazy::new(|| Selector::parse("div.il_ContainerListItem, .il-std-item").unwrap()); +static CONTAINER_ITEM_TITLE: Lazy = + Lazy::new(|| Selector::parse("a.il_ContainerItemTitle, .il-item-title > a").unwrap()); pub struct ILIAS { pub opt: Opt, @@ -341,7 +343,7 @@ impl Object { | Generic { name, .. } => &name, Thread { url } => &url.thr_pk.as_ref().unwrap(), Video { url } => &url.url, - Dashboard { url } => &url.url + Dashboard { url } => &url.url, } } diff --git a/src/ilias/folder.rs b/src/ilias/folder.rs index 92cbfb2..f977fae 100644 --- a/src/ilias/folder.rs +++ b/src/ilias/folder.rs @@ -1,4 +1,4 @@ -use std::{path::Path, sync::Arc, collections::HashSet}; +use std::{collections::HashSet, path::Path, sync::Arc}; use anyhow::{Context, Result}; @@ -23,9 +23,7 @@ pub async fn download(path: &Path, ilias: Arc, url: &URL) -> Result<()> { let mut names = HashSet::new(); for item in content.0 { let item = item?; - let item_name = file_escape( - ilias.course_names.get(item.name()).map(|x| &**x).unwrap_or(item.name()), - ); + let item_name = file_escape(ilias.course_names.get(item.name()).map(|x| &**x).unwrap_or(item.name())); if names.contains(&item_name) { warning!(format => "folder {} contains duplicated folder {:?}", path.display(), item_name); } diff --git a/src/ilias/plugin_dispatch.rs b/src/ilias/plugin_dispatch.rs index e21ea85..8e6ce5a 100644 --- a/src/ilias/plugin_dispatch.rs +++ b/src/ilias/plugin_dispatch.rs @@ -14,7 +14,9 @@ static LINKS: Lazy = Lazy::new(|| Selector::parse("a").unwrap()); static A_TARGET_BLANK: Lazy = Lazy::new(|| Selector::parse(r#"a[target="_blank"]"#).unwrap()); static VIDEO_ROWS: Lazy = Lazy::new(|| Selector::parse(".ilTableOuter > div > table > tbody > tr").unwrap()); static TABLE_CELLS: Lazy = Lazy::new(|| Selector::parse("td").unwrap()); -static LIST_URL: Lazy = Lazy::new(|| Regex::new("ilias\\.php\\?ref_id=\\d+&cmdClass=xocteventgui&cmdNode=.{9}&baseClass=ilObjPluginDispatchGUI.*&cmd=asyncGetTableGUI&cmdMode=asynch").unwrap()); +static LIST_URL: Lazy = Lazy::new(|| { + Regex::new("ilias\\.php\\?ref_id=\\d+&cmdClass=xocteventgui&cmdNode=.{9}&baseClass=ilObjPluginDispatchGUI.*&cmd=asyncGetTableGUI&cmdMode=asynch").unwrap() +}); const NO_ENTRIES: &str = "Keine Einträge"; diff --git a/src/main.rs b/src/main.rs index c01f1a2..23768f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,6 @@ use std::sync::Arc; use std::time::SystemTime; static ILIAS_URL: &str = "https://ilias.studium.kit.edu/"; -/// main personal desktop static DEFAULT_SYNC_URL: &str = "https://ilias.studium.kit.edu/ilias.php?baseClass=ilDashboardGUI&cmd=jumpToMemberships"; @@ -161,8 +160,10 @@ async fn real_main(mut opt: Opt) -> Result<()> { } let sync_url = if ilias.opt.all { - // change on ILIAS update - format!("{}ilias.php?cmdClass=ilmembershipoverviewgui&cmdNode=iy&baseClass=ilmembershipoverviewgui", ILIAS_URL) + format!( + "{}ilias.php?cmdClass=ilmembershipoverviewgui&baseClass=ilmembershipoverviewgui", + ILIAS_URL + ) } else { ilias.opt.sync_url.as_deref().unwrap_or(DEFAULT_SYNC_URL).to_owned() };