worf-warden, do not show ui on rbw error
This commit is contained in:
parent
e39b006f71
commit
93fe365975
1 changed files with 23 additions and 41 deletions
|
@ -24,51 +24,34 @@ fn split_at_tab(input: &str) -> Option<(&str, &str)> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PasswordProvider {
|
impl PasswordProvider {
|
||||||
fn new(config: &Config) -> Self {
|
fn new(config: &Config) -> Result<Self, String> {
|
||||||
let output = rbw("list", Some(vec!["--fields", "id,name"]));
|
let output = rbw("list", Some(vec!["--fields", "id,name"]))?;
|
||||||
let items = match output {
|
let mut items = output
|
||||||
Ok(output) => {
|
.lines()
|
||||||
let mut items = output
|
.filter_map(|s| split_at_tab(s))
|
||||||
.lines()
|
.fold(
|
||||||
.filter_map(|s| split_at_tab(s))
|
HashMap::new(),
|
||||||
.fold(
|
|mut acc: HashMap<String, Vec<String>>, (id, name)| {
|
||||||
HashMap::new(),
|
acc.entry(name.to_owned()).or_default().push(id.to_owned());
|
||||||
|mut acc: HashMap<String, Vec<String>>, (id, name)| {
|
acc
|
||||||
acc.entry(name.to_owned()).or_default().push(id.to_owned());
|
},
|
||||||
acc
|
)
|
||||||
},
|
.iter()
|
||||||
)
|
.map(|(key, value)| {
|
||||||
.iter()
|
MenuItem::new(
|
||||||
.map(|(key, value)| {
|
key.clone(),
|
||||||
MenuItem::new(
|
|
||||||
key.clone(),
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
vec![].into_iter().collect(),
|
|
||||||
None,
|
|
||||||
0.0,
|
|
||||||
Some(MenuItemMetaData { ids: value.clone() }),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
gui::apply_sort(&mut items, &config.sort_order());
|
|
||||||
items
|
|
||||||
}
|
|
||||||
Err(error) => {
|
|
||||||
let item = MenuItem::new(
|
|
||||||
format!("Error from rbw: {error}"),
|
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
vec![].into_iter().collect(),
|
vec![].into_iter().collect(),
|
||||||
None,
|
None,
|
||||||
0.0,
|
0.0,
|
||||||
None,
|
Some(MenuItemMetaData { ids: value.clone() }),
|
||||||
);
|
)
|
||||||
vec![item]
|
})
|
||||||
}
|
.collect::<Vec<_>>();
|
||||||
};
|
gui::apply_sort(&mut items, &config.sort_order());
|
||||||
|
|
||||||
Self { items }
|
Ok(Self { items })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sub_provider(ids: Vec<String>) -> Result<Self, String> {
|
fn sub_provider(ids: Vec<String>) -> Result<Self, String> {
|
||||||
|
@ -376,7 +359,6 @@ fn main() -> Result<(), String> {
|
||||||
spawn_fork("ydotoold", None).expect("failed to spawn ydotoold");
|
spawn_fork("ydotoold", None).expect("failed to spawn ydotoold");
|
||||||
|
|
||||||
// todo eventually use a propper rust client for this, for now rbw is good enough
|
// todo eventually use a propper rust client for this, for now rbw is good enough
|
||||||
let provider = PasswordProvider::new(&config);
|
let provider = PasswordProvider::new(&config)?;
|
||||||
|
|
||||||
show(config, provider)
|
show(config, provider)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue