Improve CLI arguments and help text
This commit is contained in:
parent
b7cedea8eb
commit
30b22de2b9
3 changed files with 25 additions and 25 deletions
46
src/main.rs
46
src/main.rs
|
|
@ -10,20 +10,19 @@ use anyhow::Result;
|
|||
use clap::{Parser, ValueEnum};
|
||||
|
||||
#[derive(ValueEnum, Copy, Clone, Eq, PartialEq)]
|
||||
enum Modes {
|
||||
/// Generate a report containing projected work for the day and a morning message
|
||||
enum ReportTypes {
|
||||
/// report projected work for the day and a morning message
|
||||
Morning,
|
||||
/// Generate a report that is intended to be used for sharing what major tasks were completed
|
||||
/// in the last cycle.
|
||||
/// report what major tasks were completed in the last cycle.
|
||||
Cycle,
|
||||
/// Generate a report for what was actually done today and a signoff message
|
||||
/// report what was actually done today and a signoff message
|
||||
Signoff,
|
||||
}
|
||||
|
||||
impl Modes {
|
||||
impl ReportTypes {
|
||||
fn format_tasks(&self, tasks: Vec<Task>, tags: &Vec<String>, sanitize_names: bool) -> String {
|
||||
match self {
|
||||
Modes::Morning => {
|
||||
ReportTypes::Morning => {
|
||||
let task_report = MarkdownReporter.report(tasks, &ReportOptions {
|
||||
resolution: Resolution::FullTask,
|
||||
tags: tags.to_vec(),
|
||||
|
|
@ -31,7 +30,7 @@ impl Modes {
|
|||
});
|
||||
format!("{}\n\n{}", emoji::pick(3).join(" "), task_report)
|
||||
},
|
||||
Modes::Signoff => {
|
||||
ReportTypes::Signoff => {
|
||||
let task_report = MarkdownReporter.report(tasks, &ReportOptions {
|
||||
resolution: Resolution::FullTask,
|
||||
tags: tags.to_vec(),
|
||||
|
|
@ -39,7 +38,7 @@ impl Modes {
|
|||
});
|
||||
format!("Stopping now\n\n{}", task_report)
|
||||
},
|
||||
Modes::Cycle => {
|
||||
ReportTypes::Cycle => {
|
||||
let further_filtered = tasks.into_iter().filter(|t| {
|
||||
if let Some(p) = &t.project {
|
||||
return p.status == Status::Completed;
|
||||
|
|
@ -57,42 +56,43 @@ impl Modes {
|
|||
}
|
||||
}
|
||||
|
||||
impl Default for Modes {
|
||||
fn default() -> Modes {
|
||||
Modes::Morning
|
||||
impl Default for ReportTypes {
|
||||
fn default() -> ReportTypes {
|
||||
ReportTypes::Morning
|
||||
}
|
||||
}
|
||||
|
||||
/// A program that generates Slack flavor markdown reports from Things 3 todo list items.
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
struct CliArgs {
|
||||
/// A list of tags to filter requests on
|
||||
/// A list of tags to filter todos by. Only todo list items with every tag will be reported
|
||||
#[arg(short, long)]
|
||||
tags: Vec<String>,
|
||||
|
||||
/// Control what type of report to generate
|
||||
#[arg(short, long, default_value_t = Modes::default())]
|
||||
/// Select the type of report to generate
|
||||
#[arg(short, long, default_value_t = ReportTypes::default())]
|
||||
#[clap(value_enum)]
|
||||
mode: Modes,
|
||||
report: ReportTypes,
|
||||
|
||||
/// By default, any @<name> style tags will be sanitized in the output to avoid @-mentions in
|
||||
/// slack. This is done by replacing vowel characters with look unicode lookalikes. If this
|
||||
/// flag is set then the names will be passed through unsanitized
|
||||
/// Slack. This is done by replacing vowel characters with unicode lookalikes. If this
|
||||
/// flag is set then the names will be passed through unsanitized.
|
||||
#[arg(long, default_value_t = false)]
|
||||
no_sanitize: bool,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = CliArgs::parse();
|
||||
let tasks = match args.mode {
|
||||
Modes::Morning => Task::today(),
|
||||
Modes::Signoff => Task::logbook_today(),
|
||||
Modes::Cycle => Task::logbook_this_cycle(),
|
||||
let tasks = match args.report {
|
||||
ReportTypes::Morning => Task::today(),
|
||||
ReportTypes::Signoff => Task::logbook_today(),
|
||||
ReportTypes::Cycle => Task::logbook_this_cycle(),
|
||||
}?;
|
||||
let reported: Vec<Task> = tasks.into_iter().filter(|task| {
|
||||
args.tags.iter().all(|tag| task.has_tag(tag))
|
||||
}).collect();
|
||||
let report = args.mode.format_tasks(reported, &args.tags, !args.no_sanitize);
|
||||
let report = args.report.format_tasks(reported, &args.tags, !args.no_sanitize);
|
||||
println!("{report}");
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
Reference in a new issue