2021-08-14 12:06:07 -05:00
|
|
|
use clap::{
|
2023-03-11 19:29:09 -06:00
|
|
|
Command, Arg, SubCommand, command, value_parser,
|
2021-07-01 23:44:38 -05:00
|
|
|
};
|
2021-06-18 11:27:19 -05:00
|
|
|
|
2023-03-11 19:29:09 -06:00
|
|
|
pub fn make_cli() -> Command<'static> {
|
2022-08-26 11:33:56 -05:00
|
|
|
// Let's first declare some args that repeat here and there
|
2021-07-07 12:10:57 -05:00
|
|
|
let start_arg = Arg::with_name("start")
|
2023-02-13 18:17:47 -06:00
|
|
|
.long("start").short('s')
|
2021-07-07 12:10:57 -05:00
|
|
|
.takes_value(true).value_name("TIME")
|
|
|
|
.help("Include entries that start on this date or later");
|
|
|
|
|
|
|
|
let end_arg = Arg::with_name("end")
|
2023-02-13 18:17:47 -06:00
|
|
|
.long("end").short('e')
|
2021-07-07 12:10:57 -05:00
|
|
|
.takes_value(true).value_name("TIME")
|
|
|
|
.help("Include entries that start on this date or earlier");
|
|
|
|
|
|
|
|
let ids_arg = Arg::with_name("ids")
|
2023-02-13 18:17:47 -06:00
|
|
|
.short('v').long("ids")
|
2021-07-07 12:10:57 -05:00
|
|
|
.help("Print database ids (for use with edit)");
|
|
|
|
|
|
|
|
let grep_arg = Arg::with_name("grep")
|
2023-02-13 18:17:47 -06:00
|
|
|
.long("grep").short('g')
|
2021-07-07 12:10:57 -05:00
|
|
|
.takes_value(true).value_name("REGEXP")
|
2022-09-25 17:14:06 -05:00
|
|
|
.help("Only include entries whose note matches this regular expression");
|
2021-07-07 12:10:57 -05:00
|
|
|
|
|
|
|
let format_arg = Arg::with_name("format")
|
2023-02-13 18:17:47 -06:00
|
|
|
.short('f').long("format")
|
2021-08-19 20:50:34 -05:00
|
|
|
.takes_value(true).value_name("FORMAT")
|
2021-07-07 12:10:57 -05:00
|
|
|
.help(
|
2022-08-31 07:19:16 -05:00
|
|
|
"The output format. Valid built-in formats are chart, text, ical, \
|
2022-08-31 07:44:55 -05:00
|
|
|
csv, json and ids. Documentation on defining custom formats can be \
|
2022-09-25 17:14:06 -05:00
|
|
|
found at https://tiempo.categulario.xyz or the man page included \
|
|
|
|
with the installation."
|
2021-07-07 12:10:57 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
let sheet_arg = Arg::with_name("sheet")
|
|
|
|
.takes_value(true).value_name("SHEET")
|
|
|
|
.help(
|
|
|
|
"The sheet to display. Pass 'all' to see entries from all sheets \
|
|
|
|
or 'full' to see hidden entries"
|
|
|
|
);
|
|
|
|
|
2021-07-10 14:17:59 -05:00
|
|
|
let at_arg = Arg::with_name("at")
|
|
|
|
.long("at")
|
|
|
|
.takes_value(true).value_name("TIME")
|
|
|
|
.help("Use this time instead of now");
|
|
|
|
|
|
|
|
let id_arg = Arg::with_name("id")
|
|
|
|
.long("id")
|
|
|
|
.takes_value(true).value_name("ID")
|
2023-02-13 18:17:47 -06:00
|
|
|
.value_parser(value_parser!(u64));
|
2021-07-10 14:17:59 -05:00
|
|
|
|
2022-05-07 10:10:38 -05:00
|
|
|
let interactive_arg = Arg::with_name("interactive")
|
2023-02-13 18:17:47 -06:00
|
|
|
.short('i')
|
2022-05-07 10:10:38 -05:00
|
|
|
.long("interactive")
|
|
|
|
.takes_value(false)
|
|
|
|
.conflicts_with("id")
|
|
|
|
.help("Choose an entry of the (unique) last N interactively");
|
|
|
|
|
2021-07-07 12:10:57 -05:00
|
|
|
// Now declar this app's cli
|
2023-03-11 19:29:09 -06:00
|
|
|
let cli = command!()
|
2023-02-13 19:58:13 -06:00
|
|
|
.subcommand_required(true)
|
2021-06-18 11:27:19 -05:00
|
|
|
|
|
|
|
.subcommand(SubCommand::with_name("archive")
|
|
|
|
.visible_alias("a")
|
|
|
|
.about("Move entries to a hidden sheet (by default named '_[SHEET]') so they're out of the way.")
|
2021-07-07 12:10:57 -05:00
|
|
|
.arg(start_arg.clone())
|
|
|
|
.arg(end_arg.clone())
|
|
|
|
.arg(grep_arg.clone())
|
2021-08-11 20:25:32 -05:00
|
|
|
.arg(sheet_arg.clone().help("Archive entries from this sheet instead of the current one"))
|
2021-08-09 10:13:51 -05:00
|
|
|
.arg(Arg::with_name("fake")
|
2023-02-13 18:17:47 -06:00
|
|
|
.short('f').long("fake")
|
2021-08-09 10:13:51 -05:00
|
|
|
.help("Don't actually archive the entries, just display them")
|
|
|
|
)
|
2022-08-02 18:55:15 -05:00
|
|
|
.arg(Arg::with_name("time")
|
2023-02-13 18:17:47 -06:00
|
|
|
.short('t').long("time")
|
2022-08-03 08:54:25 -05:00
|
|
|
.takes_value(true).value_name("HOURS")
|
2022-08-02 18:55:15 -05:00
|
|
|
.help("Time in hours to archive. Archived time will be equal or less than this.")
|
|
|
|
)
|
2021-06-18 11:27:19 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
.subcommand(SubCommand::with_name("backend")
|
|
|
|
.visible_alias("b")
|
|
|
|
.about("Open an sqlite shell to the database.")
|
|
|
|
)
|
|
|
|
|
|
|
|
.subcommand(SubCommand::with_name("configure")
|
|
|
|
.visible_alias("c")
|
2021-08-14 11:09:37 -05:00
|
|
|
.about("Configure tiempo in-place. If no arguments are given it just prints the path to the config file in use.")
|
2021-06-18 11:27:19 -05:00
|
|
|
.arg(Arg::with_name("round_in_seconds")
|
|
|
|
.long("round-in-seconds")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("SECONDS")
|
2023-02-13 18:17:47 -06:00
|
|
|
.value_parser(value_parser!(u64))
|
2021-08-14 11:09:37 -05:00
|
|
|
.help("The duration of time to use for rounding with the -r flag. Default: 900 (15 m)"))
|
2021-06-18 11:27:19 -05:00
|
|
|
.arg(Arg::with_name("database_file")
|
|
|
|
.long("database-file")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("PATH")
|
|
|
|
.help("The file path of the sqlite database"))
|
|
|
|
.arg(Arg::with_name("append_notes_delimiter")
|
|
|
|
.long("append-notes-delimiter")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("DELIMITER")
|
2021-08-14 11:09:37 -05:00
|
|
|
.help("delimiter used when appending notes via t edit --append. Default: ' ' (space)"))
|
2021-06-18 11:27:19 -05:00
|
|
|
.arg(Arg::with_name("formatter_search_paths")
|
|
|
|
.long("formatter-search-paths")
|
|
|
|
.takes_value(true)
|
2021-08-14 11:09:37 -05:00
|
|
|
.multiple(true)
|
2021-06-18 11:27:19 -05:00
|
|
|
.value_name("PATHS")
|
|
|
|
.help("comma separated directories to search for user defined fomatter classes"))
|
|
|
|
.arg(Arg::with_name("default_formatter")
|
|
|
|
.long("default-formatter")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("FORMATTER")
|
2021-08-14 11:09:37 -05:00
|
|
|
.help("The format to use when display is invoked without a `--format` option. Default 'text'"))
|
2021-06-18 11:27:19 -05:00
|
|
|
.arg(Arg::with_name("require_note")
|
|
|
|
.long("require-note")
|
2021-08-14 11:09:37 -05:00
|
|
|
.help("Prompt for a note if one isn't provided when checking in (default)"))
|
2021-06-18 11:27:19 -05:00
|
|
|
.arg(Arg::with_name("no_require_note")
|
|
|
|
.long("no-require-note")
|
2021-08-14 11:09:37 -05:00
|
|
|
.help("Entries can be created without notes"))
|
|
|
|
.arg(Arg::with_name("auto_checkout")
|
|
|
|
.long("auto-checkout")
|
|
|
|
.help("Checkout of current running entry when starting a new one"))
|
|
|
|
.arg(Arg::with_name("no_auto_checkout")
|
|
|
|
.long("no-auto-checkout")
|
|
|
|
.help("Starting a new entry fails if one is running (default)"))
|
2021-06-18 11:27:19 -05:00
|
|
|
.arg(Arg::with_name("note_editor")
|
|
|
|
.long("note-editor")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("EDITOR")
|
2021-08-14 11:09:37 -05:00
|
|
|
.help("Command to launch notes editor. Default: $EDITOR"))
|
2021-06-18 11:27:19 -05:00
|
|
|
.arg(Arg::with_name("week_start")
|
|
|
|
.long("week-start")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("DAY")
|
2023-02-13 18:17:47 -06:00
|
|
|
.possible_values(["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"])
|
2021-08-14 11:09:37 -05:00
|
|
|
.help("The day of the week to use as the start of the week for t week. Default: monday"))
|
2022-05-07 10:10:38 -05:00
|
|
|
.arg(Arg::with_name("interactive_entries")
|
|
|
|
.long("interactive-entries")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("N")
|
2023-02-13 18:17:47 -06:00
|
|
|
.value_parser(value_parser!(u64))
|
2022-05-07 10:10:38 -05:00
|
|
|
.help("How many unique previous notes to show when selecting interactively"))
|
2021-06-18 11:27:19 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
.subcommand(SubCommand::with_name("display")
|
|
|
|
.visible_alias("d")
|
2021-07-21 19:07:19 -05:00
|
|
|
.about(
|
|
|
|
"Display the current timesheet or a specific. Pass `all' as \
|
|
|
|
SHEET to display all unarchived sheets or `full' to display \
|
|
|
|
archived and unarchived sheets.")
|
2021-07-07 12:10:57 -05:00
|
|
|
.arg(ids_arg.clone())
|
|
|
|
.arg(start_arg.clone())
|
|
|
|
.arg(end_arg.clone())
|
|
|
|
.arg(format_arg.clone())
|
|
|
|
.arg(grep_arg.clone())
|
|
|
|
.arg(sheet_arg.clone())
|
2021-07-06 22:52:20 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
.subcommand(SubCommand::with_name("today")
|
|
|
|
.visible_alias("t")
|
|
|
|
.about("Display entries that started today")
|
2021-07-07 12:10:57 -05:00
|
|
|
.arg(ids_arg.clone())
|
|
|
|
.arg(end_arg.clone())
|
|
|
|
.arg(format_arg.clone())
|
|
|
|
.arg(grep_arg.clone())
|
|
|
|
.arg(sheet_arg.clone())
|
2021-06-18 11:27:19 -05:00
|
|
|
)
|
|
|
|
|
2021-07-07 11:58:13 -05:00
|
|
|
.subcommand(SubCommand::with_name("yesterday")
|
|
|
|
.visible_alias("y")
|
|
|
|
.about("Display entries that started yesterday")
|
2021-07-07 12:10:57 -05:00
|
|
|
.arg(ids_arg.clone())
|
|
|
|
.arg(format_arg.clone())
|
|
|
|
.arg(grep_arg.clone())
|
|
|
|
.arg(sheet_arg.clone())
|
2021-07-07 11:58:13 -05:00
|
|
|
)
|
|
|
|
|
2021-07-07 13:44:19 -05:00
|
|
|
.subcommand(SubCommand::with_name("week")
|
|
|
|
.visible_alias("w")
|
|
|
|
.about("Display entries starting last monday or later")
|
|
|
|
.arg(ids_arg.clone())
|
|
|
|
.arg(end_arg.clone())
|
|
|
|
.arg(format_arg.clone())
|
|
|
|
.arg(grep_arg.clone())
|
|
|
|
.arg(sheet_arg.clone())
|
|
|
|
)
|
|
|
|
|
2021-07-07 13:52:40 -05:00
|
|
|
.subcommand(SubCommand::with_name("month")
|
|
|
|
.visible_alias("m")
|
|
|
|
.about("Display entries starting this month")
|
|
|
|
.arg(ids_arg.clone())
|
|
|
|
.arg(format_arg.clone())
|
|
|
|
.arg(grep_arg.clone())
|
|
|
|
.arg(sheet_arg.clone())
|
2021-07-10 13:20:42 -05:00
|
|
|
.arg(Arg::with_name("month")
|
2023-02-13 18:17:47 -06:00
|
|
|
.long("month").short('m')
|
2021-07-10 13:20:42 -05:00
|
|
|
.takes_value(true).value_name("TIME")
|
|
|
|
.aliases(&["s", "start"])
|
2023-02-13 18:17:47 -06:00
|
|
|
.possible_values([
|
2021-07-10 13:27:38 -05:00
|
|
|
"this", "current", "last", "jan", "january", "feb",
|
|
|
|
"february", "mar", "march", "apr", "april", "may", "jun",
|
|
|
|
"june", "jul", "july", "aug", "august", "sep", "september",
|
|
|
|
"oct", "october", "nov", "november", "dic", "december",
|
2021-07-10 13:20:42 -05:00
|
|
|
])
|
|
|
|
.hide_possible_values(true)
|
|
|
|
.help(
|
|
|
|
"Include entries of the specified month instead of the \
|
|
|
|
current month"
|
|
|
|
)
|
|
|
|
)
|
2021-07-07 13:52:40 -05:00
|
|
|
)
|
|
|
|
|
2021-06-18 11:27:19 -05:00
|
|
|
.subcommand(SubCommand::with_name("in")
|
|
|
|
.visible_alias("i")
|
|
|
|
.about("Start an activity in the current timesheet")
|
2021-07-10 14:17:59 -05:00
|
|
|
.arg(at_arg.clone())
|
2021-06-18 11:27:19 -05:00
|
|
|
.arg(Arg::with_name("note")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("NOTE")
|
|
|
|
.help("Text describing the activity to start"))
|
|
|
|
)
|
|
|
|
|
2021-07-10 14:17:59 -05:00
|
|
|
.subcommand(SubCommand::with_name("resume")
|
|
|
|
.visible_alias("r")
|
|
|
|
.about("Restart the timer for an entry. Defaults to the last active entry")
|
|
|
|
.arg(at_arg.clone())
|
2021-07-30 17:55:19 -05:00
|
|
|
.arg(id_arg.clone().help("Use entry with ID instead of the last entry"))
|
2022-05-07 10:10:38 -05:00
|
|
|
.arg(interactive_arg.clone())
|
2021-07-10 14:17:59 -05:00
|
|
|
)
|
|
|
|
|
2021-06-18 11:27:19 -05:00
|
|
|
.subcommand(SubCommand::with_name("out")
|
|
|
|
.visible_alias("o")
|
|
|
|
.about("end the active entry in the current timesheet")
|
2021-07-30 12:52:06 -05:00
|
|
|
.arg(at_arg.clone())
|
2021-06-18 11:27:19 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
.subcommand(SubCommand::with_name("sheet")
|
|
|
|
.visible_alias("s")
|
|
|
|
.about("Change active timesheet or list existing timesheets")
|
2021-09-17 12:41:43 -05:00
|
|
|
.arg(sheet_arg.clone().help("The sheet to switch to. Use - to quickly switch to the previous sheet"))
|
2021-07-14 12:37:45 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
.subcommand(SubCommand::with_name("list")
|
|
|
|
.visible_alias("l")
|
|
|
|
.about("List existing sheets")
|
|
|
|
.arg(Arg::with_name("all")
|
2023-02-13 18:17:47 -06:00
|
|
|
.short('a').long("all")
|
2021-07-14 12:37:45 -05:00
|
|
|
.help("List archive sheets also"))
|
2022-11-04 21:56:41 -06:00
|
|
|
.arg(Arg::with_name("flat")
|
2023-02-13 18:17:47 -06:00
|
|
|
.short('f').long("flat")
|
2022-11-04 21:56:41 -06:00
|
|
|
.help("show only the sheet names"))
|
2021-06-18 11:27:19 -05:00
|
|
|
)
|
|
|
|
|
2021-07-30 17:55:19 -05:00
|
|
|
.subcommand(SubCommand::with_name("kill")
|
|
|
|
.visible_alias("k")
|
|
|
|
.about("Delete an entry or an entire sheet")
|
|
|
|
.arg(id_arg.clone().help("Delete entry with this ID instead of sheet"))
|
|
|
|
.arg(Arg::with_name("sheet")
|
|
|
|
.takes_value(true).value_name("SHEET")
|
2022-05-07 22:37:05 -05:00
|
|
|
.conflicts_with_all(&["id", "last"])
|
2023-02-13 18:17:47 -06:00
|
|
|
.required_unless_one(["id", "last"])
|
2021-07-30 17:55:19 -05:00
|
|
|
.help(
|
|
|
|
"Delete an entire sheet by its name"
|
|
|
|
))
|
2022-05-07 22:37:05 -05:00
|
|
|
.arg(Arg::with_name("last")
|
2023-02-13 18:17:47 -06:00
|
|
|
.short('l').long("last")
|
2022-05-07 22:37:05 -05:00
|
|
|
.takes_value(false)
|
|
|
|
.help("Delete the last entry of the current sheet"))
|
2021-07-30 17:55:19 -05:00
|
|
|
)
|
|
|
|
|
2021-08-02 18:45:54 -05:00
|
|
|
.subcommand(SubCommand::with_name("now")
|
|
|
|
.visible_alias("n")
|
|
|
|
.about("Show all running entries")
|
|
|
|
)
|
|
|
|
|
2021-08-03 20:58:26 -05:00
|
|
|
.subcommand(SubCommand::with_name("edit")
|
|
|
|
.visible_alias("e")
|
|
|
|
.about("Edit an entry")
|
|
|
|
.arg(id_arg.clone().help("Edit entry with this ID instead of the last one in the current sheet"))
|
|
|
|
.arg(start_arg.clone().help("Set this as the start time"))
|
|
|
|
.arg(end_arg.clone().help("Set this as the end time"))
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("append")
|
2023-02-13 18:17:47 -06:00
|
|
|
.long("append").short('z')
|
2021-08-03 20:58:26 -05:00
|
|
|
.help("Append to the current note instead of replacing it. The delimiter between appended notes is configurable (see configure)")
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("move")
|
2023-02-13 18:17:47 -06:00
|
|
|
.short('m').long("move")
|
2021-08-03 20:58:26 -05:00
|
|
|
.takes_value(true)
|
|
|
|
.value_name("SHEET")
|
|
|
|
.help("Move entry to another sheet")
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("note")
|
|
|
|
.takes_value(true)
|
|
|
|
.value_name("NOTE")
|
|
|
|
.help("The note text. It will replace the previous one unless --append is given")
|
|
|
|
)
|
2023-03-11 19:29:09 -06:00
|
|
|
);
|
2021-06-18 11:27:19 -05:00
|
|
|
|
2023-03-11 19:29:09 -06:00
|
|
|
cli
|
2021-06-18 11:27:19 -05:00
|
|
|
}
|