diff options
Diffstat (limited to 'bin/core/imag-grep/src/ui.rs')
-rw-r--r-- | bin/core/imag-grep/src/ui.rs | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/bin/core/imag-grep/src/ui.rs b/bin/core/imag-grep/src/ui.rs index 7b05172c..7c4fd2f5 100644 --- a/bin/core/imag-grep/src/ui.rs +++ b/bin/core/imag-grep/src/ui.rs @@ -17,10 +17,18 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // -use clap::{Arg, App}; +use std::path::PathBuf; + +use clap::{Arg, ArgMatches, App}; +use anyhow::Result; + +use libimagstore::storeid::IntoStoreId; +use libimagstore::storeid::StoreId; +use libimagrt::runtime::IdPathProvider; pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { app + .arg(Arg::with_name("files-with-matches") .long("files-with-matches") .short("l") @@ -44,4 +52,26 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { .multiple(false) .value_name("PATTERN") .help("Pattern to search for. Regex is supported, multiple patterns are not.")) + + .arg(Arg::with_name("entry") + .index(2) + .takes_value(true) + .required(false) + .multiple(true) + .help("The entry/entries to grep in") + .value_name("ENTRY")) +} + +pub struct PathProvider; +impl IdPathProvider for PathProvider { + fn get_ids(matches: &ArgMatches) -> Result<Option<Vec<StoreId>>> { + matches.values_of("entry") + .map(|v| v + .map(PathBuf::from) + .map(|pb| pb.into_storeid()) + .collect::<Result<Vec<_>>>() + ) + .transpose() + } } + |