rustfmt
This commit is contained in:
parent
eaafe61635
commit
57a3955925
62
src/main.rs
62
src/main.rs
|
@ -65,40 +65,38 @@ fn main() {
|
||||||
|
|
||||||
// Figure out what accounts we have to deal with
|
// Figure out what accounts we have to deal with
|
||||||
let accounts: Vec<_> = match config.as_table() {
|
let accounts: Vec<_> = match config.as_table() {
|
||||||
Some(t) => {
|
Some(t) => t.iter()
|
||||||
t.iter()
|
.filter_map(|(name, v)| match v.as_table() {
|
||||||
.filter_map(|(name, v)| match v.as_table() {
|
None => {
|
||||||
None => {
|
println!("Configuration for account {} is broken: not a table", name);
|
||||||
println!("Configuration for account {} is broken: not a table", name);
|
None
|
||||||
None
|
}
|
||||||
}
|
Some(t) => {
|
||||||
Some(t) => {
|
let pwcmd = match t.get("pwcmd").and_then(|p| p.as_str()) {
|
||||||
let pwcmd = match t.get("pwcmd").and_then(|p| p.as_str()) {
|
None => return None,
|
||||||
None => return None,
|
Some(pwcmd) => pwcmd,
|
||||||
Some(pwcmd) => pwcmd,
|
};
|
||||||
};
|
|
||||||
|
|
||||||
let password = match Command::new("sh").arg("-c").arg(pwcmd).output() {
|
let password = match Command::new("sh").arg("-c").arg(pwcmd).output() {
|
||||||
Ok(output) => String::from_utf8_lossy(&output.stdout).into_owned(),
|
Ok(output) => String::from_utf8_lossy(&output.stdout).into_owned(),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("Failed to launch password command for {}: {}", name, e);
|
println!("Failed to launch password command for {}: {}", name, e);
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(Account {
|
Some(Account {
|
||||||
name: name,
|
name: name,
|
||||||
server: (
|
server: (
|
||||||
t["server"].as_str().unwrap(),
|
t["server"].as_str().unwrap(),
|
||||||
t["port"].as_integer().unwrap() as u16,
|
t["port"].as_integer().unwrap() as u16,
|
||||||
),
|
),
|
||||||
username: t["username"].as_str().unwrap(),
|
username: t["username"].as_str().unwrap(),
|
||||||
password: password,
|
password: password,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect()
|
.collect(),
|
||||||
}
|
|
||||||
None => {
|
None => {
|
||||||
println!("Could not parse configuration file buzz.toml: not a table");
|
println!("Could not parse configuration file buzz.toml: not a table");
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue