Apply rustfmt

This commit is contained in:
FliegendeWurst 2022-10-21 09:47:16 +02:00
parent e3208a1579
commit f2c9ce5fa0
5 changed files with 34 additions and 32 deletions

View File

@ -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 {

View File

@ -28,8 +28,10 @@ static ALERT_DANGER: Lazy<Selector> = Lazy::new(|| Selector::parse("div.alert-da
static IL_CONTENT_CONTAINER: Lazy<Selector> = Lazy::new(|| Selector::parse("#il_center_col").unwrap());
static BLOCK_FAVORITES: Lazy<Selector> = Lazy::new(|| Selector::parse("#block_pditems_0").unwrap());
static ITEM_PROP: Lazy<Selector> = Lazy::new(|| Selector::parse("span.il_ItemProperty").unwrap());
static CONTAINER_ITEMS: Lazy<Selector> = Lazy::new(|| Selector::parse("div.il_ContainerListItem, .il-std-item").unwrap());
static CONTAINER_ITEM_TITLE: Lazy<Selector> = Lazy::new(|| Selector::parse("a.il_ContainerItemTitle, .il-item-title > a").unwrap());
static CONTAINER_ITEMS: Lazy<Selector> =
Lazy::new(|| Selector::parse("div.il_ContainerListItem, .il-std-item").unwrap());
static CONTAINER_ITEM_TITLE: Lazy<Selector> =
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,
}
}

View File

@ -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<ILIAS>, 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);
}

View File

@ -14,7 +14,9 @@ static LINKS: Lazy<Selector> = Lazy::new(|| Selector::parse("a").unwrap());
static A_TARGET_BLANK: Lazy<Selector> = Lazy::new(|| Selector::parse(r#"a[target="_blank"]"#).unwrap());
static VIDEO_ROWS: Lazy<Selector> = Lazy::new(|| Selector::parse(".ilTableOuter > div > table > tbody > tr").unwrap());
static TABLE_CELLS: Lazy<Selector> = Lazy::new(|| Selector::parse("td").unwrap());
static LIST_URL: Lazy<Regex> = Lazy::new(|| Regex::new("ilias\\.php\\?ref_id=\\d+&cmdClass=xocteventgui&cmdNode=.{9}&baseClass=ilObjPluginDispatchGUI.*&cmd=asyncGetTableGUI&cmdMode=asynch").unwrap());
static LIST_URL: Lazy<Regex> = 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";

View File

@ -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()
};