show list of projects

This commit is contained in:
Schmidt-Voigt_N 2021-07-19 10:21:18 +02:00
parent 592efb5e24
commit 6bc6287635
2 changed files with 23 additions and 1 deletions

View file

@ -89,6 +89,24 @@ pub fn list(file_name: &str, filter: ActivityFilter, do_group_activities: bool)
Ok(())
}
// lists all projects
pub fn list_projects(file_name: &str) -> Result<()> {
let file_content = bartib_file::get_file_content(file_name)?;
let mut all_projects : Vec<&String> = get_activities(&file_content)
.map(|activity| &activity.project)
.collect();
all_projects.sort_unstable();
all_projects.dedup();
for project in all_projects {
println!("{}", project);
}
Ok(())
}
fn get_index_of_first_element(length: usize, sub: Option<usize>) -> usize {
if let Some(s) = sub {
length.saturating_sub(s)

View file

@ -85,6 +85,9 @@ fn main() -> Result<()> {
.help("do not group activities by date in list"),
),
)
.subcommand(
SubCommand::with_name("projects").about("list all projects")
)
.get_matches();
let file_name = matches.value_of("file").context("Please specify a file with your activity log either as -f option or as BARTIB_FILE environment variable")?;
@ -115,7 +118,8 @@ fn run_subcommand(matches: &ArgMatches, file_name: &str) -> Result<()> {
let do_group_activities = !sub_m.is_present("no_grouping") && !filter.date.is_some();
bartib::list(file_name, filter, do_group_activities)
}
},
("projects", Some(_)) => bartib::list_projects(file_name),
_ => bail!("Unknown command"),
}
}