From f722ad25fa598a8b130c88c162b8bb8b5e6dc1cb Mon Sep 17 00:00:00 2001 From: rasul Date: Fri, 24 Apr 2020 16:44:49 -0500 Subject: [PATCH] start on the help command stuff it's nowhere near complete and isn't really operational yet but since i have it started then maybe i'll finish it one day --- src/command/command.rs | 2 +- src/command/dispatch/help.rs | 43 +++++++++++++++++++++++++++++++++--- src/command/parse.rs | 7 +++--- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/command/command.rs b/src/command/command.rs index 7461380..ede33e4 100644 --- a/src/command/command.rs +++ b/src/command/command.rs @@ -91,7 +91,7 @@ impl Parse for Command { } } - fn subcommand_help(&self, _: String) -> Option { + fn subcommand_help(&self) -> Option { match self { Self::New(command_new) => Some(command_new.help_all()), Self::Set(command_set) => Some(command_set.help_all()), diff --git a/src/command/dispatch/help.rs b/src/command/dispatch/help.rs index 8f2ad16..bca0146 100644 --- a/src/command/dispatch/help.rs +++ b/src/command/dispatch/help.rs @@ -1,16 +1,53 @@ use mio::Token; -use crate::command::Command; +use crate::command::{Command, Parse}; use crate::database::Db; use crate::queue::SendQueue; impl Command { pub fn dispatch_help( - _command: &Command, - _args: String, + command: &Command, + args: String, token: Token, _db: &mut Db, ) -> SendQueue { + if args.is_empty() { + return (token, command.commands()).into(); + } + + let (new_command, new_args) = match Command::parse(args) { + Ok((help_command, args)) => (help_command, args), + Err(e) => return (token, e.to_string()).into(), + }; + + if let Some(sub_help) = new_command.subcommand_help() { + // woo + } else { + return (token, new_command.commands()).into(); + } + + // let mut command = command; + // let mut args = args; + + // while !args.is_empty() { + // let (new_command, new_args) = match Command::parse(args) { + // Ok((help_command, args)) => (help_command, args), + // Err(e) => return (token, e.to_string()).into(), + // }; + // } + + // if let Some(sub_help) = help_command.subcommand_help() { + // return (token, sub_help).into(); + // } + SendQueue::ok(token) } } + +fn recurse_help(command: &Command, args: String) -> String { + if args.is_empty() { + return command.commands(); + } + + "".into() +} diff --git a/src/command/parse.rs b/src/command/parse.rs index 75f5bbd..d960f17 100644 --- a/src/command/parse.rs +++ b/src/command/parse.rs @@ -28,7 +28,7 @@ pub trait Parse: Clone + Default + IntoEnumIterator + PartialEq + ToString { /// Gets the `help_all()` for a subcommand. The default implementation does not support /// subcommands. You must implement the `subcommand_help()` function if you want sumcommands. - fn subcommand_help(&self, _: String) -> Option { + fn subcommand_help(&self) -> Option { None } @@ -72,7 +72,7 @@ pub trait Parse: Clone + Default + IntoEnumIterator + PartialEq + ToString { } /// List of all commands - fn commands(&self) -> Vec { + fn commands(&self) -> String { Self::iter() .filter_map(|a| { if a == Self::default() { @@ -81,7 +81,8 @@ pub trait Parse: Clone + Default + IntoEnumIterator + PartialEq + ToString { Some(a.to_string().to_lowercase()) } }) - .collect() + .collect::>() + .join(" ") } /// Parse a `Into` into a command.