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/command.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/command.rs') 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