diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-04-06 11:48:01 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-04-06 11:49:03 +0200 |
commit | a41d037bcfb568a8166e572c747faf99ebf5d015 (patch) | |
tree | cab6def092969b8be9c1b828c16559862182e3fe /libimagentrylist | |
parent | ecfdbab9474e73794c3d108979cfdc72682a8e14 (diff) |
Add lister helper function
Diffstat (limited to 'libimagentrylist')
-rw-r--r-- | libimagentrylist/src/cli.rs | 34 | ||||
-rw-r--r-- | libimagentrylist/src/error.rs | 4 |
2 files changed, 36 insertions, 2 deletions
diff --git a/libimagentrylist/src/cli.rs b/libimagentrylist/src/cli.rs index b1253c68..5a04a21a 100644 --- a/libimagentrylist/src/cli.rs +++ b/libimagentrylist/src/cli.rs @@ -1,4 +1,12 @@ -use clap::{Arg, App, SubCommand}; +use clap::{Arg, ArgMatches, App, SubCommand}; + +use libimagstore::store::FileLockEntry; + +use result::Result; +use listers::line::LineLister; +use listers::path::PathLister; +use lister::Lister; +use error::{ListError, ListErrorKind}; pub fn build_list_cli_component<'a, 'b>() -> App<'a, 'b> { SubCommand::with_name(list_subcommand_name()) @@ -48,3 +56,27 @@ pub fn list_backend_path_absolute() -> &'static str { "path-absolute" } +// TODO: Add Registry for listers where a HashMap name->lister is in and where we can fetch the +// lister from. +pub fn list_entries_with_lister<'a, I>(m: &ArgMatches, entries: I) -> Result<()> + where I: Iterator<Item = FileLockEntry<'a>> +{ + if let Some(matches) = m.subcommand_matches(list_subcommand_name()) { + if matches.is_present(list_backend_line()) { + return LineLister::new("<unknown>").list(entries) + }; + + if matches.is_present(list_backend_path()) { + return PathLister::new(false).list(entries) + } + + + if matches.is_present(list_backend_path_absolute()) { + return PathLister::new(true).list(entries) + } + + Ok(()) + } else { + Err(ListError::new(ListErrorKind::CLIError, None)) + } +} diff --git a/libimagentrylist/src/error.rs b/libimagentrylist/src/error.rs index 82f6b387..f4b3c159 100644 --- a/libimagentrylist/src/error.rs +++ b/libimagentrylist/src/error.rs @@ -10,7 +10,8 @@ use std::fmt::{Display, Formatter}; pub enum ListErrorKind { FormatError, EntryError, - IterationError + IterationError, + CLIError, } fn counter_error_type_as_str(err: &ListErrorKind) -> &'static str{ @@ -18,6 +19,7 @@ fn counter_error_type_as_str(err: &ListErrorKind) -> &'static str{ &ListErrorKind::FormatError => "FormatError", &ListErrorKind::EntryError => "EntryError", &ListErrorKind::IterationError => "IterationError", + &ListErrorKind::CLIError => "No CLI subcommand for listing entries", } } |