From 4325d8019b106d1e9d9d4e7537abfe815d56395e Mon Sep 17 00:00:00 2001 From: skoupidi Date: Thu, 12 Jun 2025 17:01:02 +0300 Subject: [PATCH] drk/interactive: help print added --- bin/drk/src/interactive.rs | 17 ++++++++++++++--- bin/drk/src/main.rs | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/bin/drk/src/interactive.rs b/bin/drk/src/interactive.rs index c0ad966bb..48ea91eff 100644 --- a/bin/drk/src/interactive.rs +++ b/bin/drk/src/interactive.rs @@ -21,7 +21,7 @@ use linenoise_rs::{ linenoise_set_completion_callback, linenoise_set_hints_callback, }; -use darkfi::{system::StoppableTask, util::path::expand_path}; +use darkfi::{cli_desc, system::StoppableTask, util::path::expand_path}; use crate::{ cli_util::{generate_completions, kaching}, @@ -29,11 +29,21 @@ use crate::{ }; // TODO: -// 1. add rest commands handling, along with their completions and hints. +// 1. add rest commands handling, along with their completions, hints and help message. // 2. add input definitions, so you input from files not just stdin. // 3. add output definitions, so you can output to files not just stdout. // 4. create a transactions cache in the wallet db, so you can use it to handle them. +/// Auxiliary function to print the help message. +fn help() { + println!("{}", cli_desc!()); + println!("Commands:"); + println!("\thelp: Prints the help message"); + println!("\tkaching: Fun"); + println!("\tping: Send a ping request to the darkfid RPC endpoint"); + println!("\tcompletions: Generate a SHELL completion script and print to stdout"); +} + /// Auxiliary function to define the interactive shell completions. fn completion(buf: &str, lc: &mut Vec) { if buf.starts_with("h") { @@ -123,7 +133,7 @@ pub async fn interactive(drk: &Drk, history_path: &str) { // Handle command match parts[0] { - "help" => println!("hhhheeeelp"), + "help" => help(), "kaching" => kaching().await, "ping" => handle_ping(drk).await, "completions" => handle_completions(&parts), @@ -144,6 +154,7 @@ fn handle_completions(parts: &[&str]) { if parts.len() != 2 { println!("Malformed `completions` command"); println!("Usage: completions {{shell}}"); + return } if let Err(e) = generate_completions(parts[1]) { diff --git a/bin/drk/src/main.rs b/bin/drk/src/main.rs index f366688c2..7b59144e2 100644 --- a/bin/drk/src/main.rs +++ b/bin/drk/src/main.rs @@ -68,6 +68,7 @@ const CONFIG_FILE_CONTENTS: &str = include_str!("../drk_config.toml"); // Dev Note: when adding/modifying args here, // don't forget to update cli_util::generate_completions() +// and interactive::help(). #[derive(Clone, Debug, Deserialize, StructOpt, StructOptToml)] #[serde(default)] #[structopt(name = "drk", about = cli_desc!())]