diff options
Diffstat (limited to 'src')
-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 { | |||
230 | Command::TrackDown(name) => { | 230 | Command::TrackDown(name) => { |
231 | _track(&name, TrackEvent::Decrement); | 231 | _track(&name, TrackEvent::Decrement); |
232 | } | 232 | } |
233 | Command::Help(input) => { | ||
234 | if let Some(topic) = input.as_ref().map(String::as_ref) { | ||
235 | self.message.set_message( | ||
236 | match topic { | ||
237 | "a" | "add" => "add <habit-name> [goal] (alias: a)", | ||
238 | "aa" | "add-auto" => "add-auto <habit-name> [goal] (alias: aa)", | ||
239 | "d" | "delete" => "delete <habit-name> (alias: d)", | ||
240 | "mprev" | "month-prev" => "month-prev (alias: mprev)", | ||
241 | "mnext" | "month-next" => "month-next (alias: mnext)", | ||
242 | "tup" | "track-up" => "track-up <auto-habit-name> (alias: tup)", | ||
243 | "tdown" | "track-down" => "track-down <auto-habit-name> (alias: tdown)", | ||
244 | "q" | "quit" => "quit", | ||
245 | "h"|"?" | "help" => "help [<command>|commands|keys] (aliases: h, ?)", | ||
246 | "cmds" | "commands" => "add, add-auto, delete, month-{prev,next}, track-{up,down}, help, quit", | ||
247 | "keys" => "TODO", // TODO (view?) | ||
248 | _ => "unknown command or help topic.", | ||
249 | } | ||
250 | ) | ||
251 | } else { | ||
252 | // TODO (view?) | ||
253 | self.message.set_message("help <command>|commands|keys") | ||
254 | } | ||
255 | } | ||
233 | Command::Quit => self.save_state(), | 256 | Command::Quit => self.save_state(), |
234 | Command::MonthNext => self.sift_forward(), | 257 | Command::MonthNext => self.sift_forward(), |
235 | Command::MonthPrev => self.sift_backward(), | 258 | 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 { | |||
59 | Delete(String), | 59 | Delete(String), |
60 | TrackUp(String), | 60 | TrackUp(String), |
61 | TrackDown(String), | 61 | TrackDown(String), |
62 | Help(Option<String>), | ||
62 | Quit, | 63 | Quit, |
63 | Blank, | 64 | Blank, |
64 | } | 65 | } |
65 | 66 | ||
66 | #[derive(Debug)] | 67 | #[derive(Debug)] |
67 | pub enum CommandLineError { | 68 | pub enum CommandLineError { |
68 | InvalidCommand(String), | 69 | InvalidCommand(String), // command name |
69 | InvalidArg(u32), // position | 70 | InvalidArg(u32), // position |
70 | NotEnoughArgs(String, u32), | 71 | NotEnoughArgs(String, u32), // command name, required no. of args |
71 | } | 72 | } |
72 | 73 | ||
73 | impl std::error::Error for CommandLineError {} | 74 | impl std::error::Error for CommandLineError {} |
@@ -134,6 +135,12 @@ impl Command { | |||
134 | } | 135 | } |
135 | return Ok(Command::TrackDown(args[0].to_string())); | 136 | return Ok(Command::TrackDown(args[0].to_string())); |
136 | } | 137 | } |
138 | "h" | "?" | "help" => { | ||
139 | if args.is_empty() { | ||
140 | return Ok(Command::Help(None)); | ||
141 | } | ||
142 | return Ok(Command::Help(Some(args[0].to_string()))); | ||
143 | } | ||
137 | "mprev" | "month-prev" => return Ok(Command::MonthPrev), | 144 | "mprev" | "month-prev" => return Ok(Command::MonthPrev), |
138 | "mnext" | "month-next" => return Ok(Command::MonthNext), | 145 | "mnext" | "month-next" => return Ok(Command::MonthNext), |
139 | "q" | "quit" => return Ok(Command::Quit), | 146 | "q" | "quit" => return Ok(Command::Quit), |