diff options
author | Akshay <nerdy@peppe.rs> | 2020-07-21 20:33:22 +0530 |
---|---|---|
committer | Akshay <nerdy@peppe.rs> | 2020-07-21 20:33:22 +0530 |
commit | 4f76460efa869317bd7065b4770c16d0146a92da (patch) | |
tree | 5578cfaec148888d00f44e1fe3c409681464bc61 | |
parent | 0eada5a463c0fe216cec69e96bf2ee05ad54a661 (diff) |
add help commandfeature/help-command
-rw-r--r-- | src/app/impl_self.rs | 23 | ||||
-rw-r--r-- | 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 <habit-name> [goal] (alias: a)", + "aa" | "add-auto" => "add-auto <habit-name> [goal] (alias: aa)", + "d" | "delete" => "delete <habit-name> (alias: d)", + "mprev" | "month-prev" => "month-prev (alias: mprev)", + "mnext" | "month-next" => "month-next (alias: mnext)", + "tup" | "track-up" => "track-up <auto-habit-name> (alias: tup)", + "tdown" | "track-down" => "track-down <auto-habit-name> (alias: tdown)", + "q" | "quit" => "quit", + "h"|"?" | "help" => "help [<command>|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 <command>|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<String>), 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), |