commit 07ae2275a7ebf94b3d413430a69ca9caff4115d7
parent 5701a8fd93a4833e3cc5ab7b128648d03122d111
Author: Antoine A <>
Date: Tue, 23 Jun 2026 10:53:33 +0200
test: improve repl
Diffstat:
1 file changed, 22 insertions(+), 7 deletions(-)
diff --git a/common/taler-test-utils/src/repl.rs b/common/taler-test-utils/src/repl.rs
@@ -16,6 +16,7 @@
use std::{borrow::Cow, marker::PhantomData};
+use clap::Command;
use nu_ansi_term::Color;
use reedline::{
ColumnarMenu, DefaultHinter, FileBackedHistory, KeyCode, KeyModifiers, MenuBuilder as _,
@@ -26,8 +27,9 @@ use reedline::{
use crate::cli::clap_parse;
pub struct Repl<T: clap::Parser> {
+ cmd: Command,
relp: Reedline,
- cmd: PhantomData<T>,
+ phantom: PhantomData<T>,
}
impl<T: clap::Parser> Repl<T> {
@@ -53,9 +55,10 @@ impl<T: clap::Parser> Repl<T> {
ReedlineEvent::MenuNext,
]),
);
+ let cmd = T::command();
let repl = Reedline::create()
.with_history(history)
- .with_completer(Box::new(ClapCompleter(T::command())))
+ .with_completer(Box::new(ClapCompleter(cmd.clone())))
.with_menu(ReedlineMenu::EngineCompleter(completion_menu))
.with_quick_completions(true)
.with_partial_completions(true)
@@ -65,8 +68,9 @@ impl<T: clap::Parser> Repl<T> {
.with_edit_mode(Box::new(Vi::new(insert, default_vi_normal_keybindings())));
Self {
+ cmd,
relp: repl,
- cmd: PhantomData,
+ phantom: PhantomData,
}
}
@@ -76,14 +80,25 @@ impl<T: clap::Parser> Repl<T> {
else {
return None;
};
- match clap_parse(&buf) {
- Ok(cmd) => return Some(cmd),
- Err(e) => {
- println!("{e}");
+ if buf.trim().is_empty() {
+ self.print_commands();
+ } else {
+ match clap_parse(&buf) {
+ Ok(cmd) => return Some(cmd),
+ Err(_) => {
+ self.print_commands();
+ }
}
}
}
}
+
+ fn print_commands(&self) {
+ for sub in self.cmd.get_subcommands() {
+ let about = sub.get_about().unwrap_or_default();
+ println!("{:<10} {}", sub.get_name(), about);
+ }
+ }
}
struct ClapCompleter(clap::Command);