mirror of
https://github.com/chmln/handlr.git
synced 2024-11-23 09:41:45 +01:00
Merge pull request #28 from benmaddison/multiple-open-#26
handle multiple 'open' paths with their correct handlers
This commit is contained in:
commit
46a59968af
1 changed files with 11 additions and 3 deletions
14
src/main.rs
14
src/main.rs
|
@ -11,8 +11,9 @@ mod error;
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
use clap::Clap;
|
use clap::Clap;
|
||||||
use cli::Cmd;
|
use cli::Cmd;
|
||||||
use common::MimeType;
|
use common::{MimeType, Handler};
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
// create config if it doesn't exist
|
// create config if it doesn't exist
|
||||||
Lazy::force(&CONFIG);
|
Lazy::force(&CONFIG);
|
||||||
|
@ -36,8 +37,15 @@ fn main() -> Result<()> {
|
||||||
apps.show_handler(&mime.0, json)?;
|
apps.show_handler(&mime.0, json)?;
|
||||||
}
|
}
|
||||||
Cmd::Open { paths } => {
|
Cmd::Open { paths } => {
|
||||||
let mime = MimeType::try_from(paths[0].as_str())?.0;
|
let mut handlers: HashMap<Handler, Vec<String>> = HashMap::new();
|
||||||
apps.get_handler(&mime)?.open(paths)?;
|
for path in paths.into_iter() {
|
||||||
|
let mime = MimeType::try_from(path.as_str())?.0;
|
||||||
|
let handler = apps.get_handler(&mime)?;
|
||||||
|
handlers.entry(handler).or_insert(Vec::new()).push(path);
|
||||||
|
}
|
||||||
|
for (handler, handled_paths) in handlers.into_iter() {
|
||||||
|
handler.open(handled_paths)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Cmd::List { all } => {
|
Cmd::List { all } => {
|
||||||
apps.print(all)?;
|
apps.print(all)?;
|
||||||
|
|
Loading…
Reference in a new issue