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
master
rasul 5 years ago
parent f929fecb73
commit f722ad25fa

@ -91,7 +91,7 @@ impl Parse for Command {
}
}
fn subcommand_help(&self, _: String) -> Option<String> {
fn subcommand_help(&self) -> Option<String> {
match self {
Self::New(command_new) => Some(command_new.help_all()),
Self::Set(command_set) => Some(command_set.help_all()),

@ -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()
}

@ -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<String> {
fn subcommand_help(&self) -> Option<String> {
None
}
@ -72,7 +72,7 @@ pub trait Parse: Clone + Default + IntoEnumIterator + PartialEq + ToString {
}
/// List of all commands
fn commands(&self) -> Vec<String> {
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::<Vec<String>>()
.join(" ")
}
/// Parse a `Into<String>` into a command.

Loading…
Cancel
Save