diff --git a/src/commands.rs b/src/commands.rs index 070d4da..0620b82 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use crate::LightClient; pub trait Command { - fn help(&self); + fn help(&self) -> String; fn short_help(&self) -> String; @@ -12,8 +12,14 @@ pub trait Command { struct SyncCommand {} impl Command for SyncCommand { - fn help(&self) { - println!("Type sync for syncing"); + fn help(&self) -> String { + let mut h = vec![]; + h.push("Sync the light client with the server"); + h.push("Usage:"); + h.push("sync"); + h.push(""); + + h.join("\n") } fn short_help(&self) -> String { @@ -27,8 +33,16 @@ impl Command for SyncCommand { struct RescanCommand {} impl Command for RescanCommand { - fn help(&self) { - println!("Rescan the wallet from it's initial state, rescanning and downloading all blocks and transactions."); + fn help(&self) -> String { + let mut h = vec![]; + h.push("Rescan the wallet, rescanning all blocks for new transactions"); + h.push("Usage:"); + h.push("rescan"); + h.push(""); + h.push("This command will download all blocks since the intial block again from the light client server"); + h.push("and attempt to scan each block for transactions belonging to the wallet."); + + h.join("\n") } fn short_help(&self) -> String { @@ -43,30 +57,58 @@ impl Command for RescanCommand { struct HelpCommand {} impl Command for HelpCommand { - fn help(&self) { - println!("Lists all available commands"); + fn help(&self) -> String { + let mut h = vec![]; + h.push("List all available commands"); + h.push("Usage:"); + h.push("help [command_name]"); + h.push(""); + h.push("If no \"command_name\" is specified, a list of all available commands is returned"); + h.push("Example:"); + h.push("help send"); + h.push(""); + + h.join("\n") } fn short_help(&self) -> String { "Lists all available commands".to_string() } - fn exec(&self, _args: &[&str], _: &LightClient) -> String { + fn exec(&self, args: &[&str], _: &LightClient) -> String { let mut responses = vec![]; - // Print a list of all commands - responses.push(format!("Available commands:")); - get_commands().iter().for_each(| (cmd, obj) | { - responses.push(format!("{} - {}", cmd, obj.short_help())); - }); - responses.join("\n") + // Print a list of all commands + match args.len() { + 0 => { + responses.push(format!("Available commands:")); + get_commands().iter().for_each(| (cmd, obj) | { + responses.push(format!("{} - {}", cmd, obj.short_help())); + }); + + responses.join("\n") + }, + 1 => { + match get_commands().get(args[0]) { + Some(cmd) => cmd.help(), + None => format!("Command {} not found", args[0]) + } + }, + _ => self.help() + } } } struct InfoCommand {} impl Command for InfoCommand { - fn help(&self) { - println!("Gets server info"); + fn help(&self) -> String { + let mut h = vec![]; + h.push("Get info about the lightwalletd we're connected to"); + h.push("Usage:"); + h.push("info"); + h.push(""); + + h.join("\n") } fn short_help(&self) -> String { @@ -81,12 +123,19 @@ impl Command for InfoCommand { struct BalanceCommand {} impl Command for BalanceCommand { - fn help(&self) { - println!("Show my balance"); + fn help(&self) -> String { + let mut h = vec![]; + h.push("Show the current TAZ balance in the wallet"); + h.push("Usage:"); + h.push("balance"); + h.push(""); + h.push("Transparent and Shielded balances, along with the addresses they belong to are displayed"); + + h.join("\n") } fn short_help(&self) -> String { - "Show the current ZEC balance in the wallet".to_string() + "Show the current TAZ balance in the wallet".to_string() } fn exec(&self, _args: &[&str], lightclient: &LightClient) -> String { @@ -98,21 +147,28 @@ impl Command for BalanceCommand { struct SendCommand {} impl Command for SendCommand { - fn help(&self) { - println!("Sends ZEC to an address"); - println!("Usage:"); - println!("send recipient_address value memo"); + fn help(&self) -> String { + let mut h = vec![]; + h.push("Send TAZ to a given address"); + h.push("Usage:"); + h.push("send