summaryrefslogtreecommitdiffstats
path: root/src/actions/list.rs
blob: 4c291882160e48a805ffc524410e0bdc03eaf116 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use crate::selectors::SelectFilters;
use crate::input;
use crate::KhResult;
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
pub struct ListArgs {
  /// the arguments for the selection
  #[structopt(name = "args")]
  pub args: Vec<String>,
}

pub fn list_by_args(args: &[&str]) -> KhResult<()> {
  let lines = input::default_input_khlines()?;
  let filters = SelectFilters::parse_from_args_with_range(args)?;

  let events = lines
    .enumerate()
    .filter(|(index, khline)| {
      match khline.to_event() {
        Ok(event) => filters.is_selected_index(*index, &event),
        Err(cause) => { warn!("{}", cause); false },
      }
    });

  for (_, khline) in events {
    khprintln!("{}", khline);
  }

  Ok(())
}