From 4f76460efa869317bd7065b4770c16d0146a92da Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 21 Jul 2020 20:33:22 +0530 Subject: add help command --- src/app/impl_self.rs | 23 +++++++++++++++++++++++ src/command.rs | 13 ++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index 2450bff..95f1871 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs @@ -230,6 +230,29 @@ impl App { Command::TrackDown(name) => { _track(&name, TrackEvent::Decrement); } + Command::Help(input) => { + if let Some(topic) = input.as_ref().map(String::as_ref) { + self.message.set_message( + match topic { + "a" | "add" => "add [goal] (alias: a)", + "aa" | "add-auto" => "add-auto [goal] (alias: aa)", + "d" | "delete" => "delete (alias: d)", + "mprev" | "month-prev" => "month-prev (alias: mprev)", + "mnext" | "month-next" => "month-next (alias: mnext)", + "tup" | "track-up" => "track-up (alias: tup)", + "tdown" | "track-down" => "track-down (alias: tdown)", + "q" | "quit" => "quit", + "h"|"?" | "help" => "help [|commands|keys] (aliases: h, ?)", + "cmds" | "commands" => "add, add-auto, delete, month-{prev,next}, track-{up,down}, help, quit", + "keys" => "TODO", // TODO (view?) + _ => "unknown command or help topic.", + } + ) + } else { + // TODO (view?) + self.message.set_message("help |commands|keys") + } + } Command::Quit => self.save_state(), Command::MonthNext => self.sift_forward(), Command::MonthPrev => self.sift_backward(), diff --git a/src/command.rs b/src/command.rs index f856b00..29908f4 100644 --- a/src/command.rs +++ b/src/command.rs @@ -59,15 +59,16 @@ pub enum Command { Delete(String), TrackUp(String), TrackDown(String), + Help(Option), Quit, Blank, } #[derive(Debug)] pub enum CommandLineError { - InvalidCommand(String), - InvalidArg(u32), // position - NotEnoughArgs(String, u32), + InvalidCommand(String), // command name + InvalidArg(u32), // position + NotEnoughArgs(String, u32), // command name, required no. of args } impl std::error::Error for CommandLineError {} @@ -134,6 +135,12 @@ impl Command { } return Ok(Command::TrackDown(args[0].to_string())); } + "h" | "?" | "help" => { + if args.is_empty() { + return Ok(Command::Help(None)); + } + return Ok(Command::Help(Some(args[0].to_string()))); + } "mprev" | "month-prev" => return Ok(Command::MonthPrev), "mnext" | "month-next" => return Ok(Command::MonthNext), "q" | "quit" => return Ok(Command::Quit), -- cgit v1.2.3