Skip to content

Commit

Permalink
feat: add option to list all builtin functions in info command
Browse files Browse the repository at this point in the history
  • Loading branch information
dwpeng committed Nov 19, 2024
1 parent c846dfe commit 0fd74ba
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/filterx/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,9 @@ pub struct GFFCommand {
#[derive(Debug, Clone, Parser)]
pub struct InfoArgs {
/// builtin function name
pub name: String,
pub name: Option<String>,

/// list all builtin functions
#[clap(long, default_value = "false", action = ArgAction::SetTrue)]
pub list: Option<bool>
}
36 changes: 32 additions & 4 deletions src/filterx/src/info.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
use crate::args::InfoArgs;
use filterx_core::FilterxResult;
use filterx_engine::eval::call::functions::get_function;
use filterx_core::{hint::Colorize, FilterxResult, Hint};
use filterx_engine::eval::call::functions::{get_function, list_functions};
use filterx_info::render;

fn list_and_print() -> FilterxResult<()> {
let functions = list_functions();
for (index, func) in functions.iter().enumerate() {
println!("{:2} {}", (index + 1), func.name.cyan().bold());
}
println!();
let mut h = Hint::new();
h.white("Use ")
.green("filterx info <function_name>")
.bold()
.white(" to get more information about a function.")
.print_and_clear();
Ok(())
}

pub fn filterx_info(info: InfoArgs) -> FilterxResult<()> {
let InfoArgs { name } = info;
let f = get_function(&name);
let InfoArgs { name, list } = info;

let list = list.unwrap();

if !list && name.is_none() {
println!("filterx info {}", "<name>".cyan());
return Ok(());
}

if list {
list_and_print()?;
return Ok(());
}

let f = get_function(&name.unwrap());
render::render_markdown_help(f.doc)?;
render::render_alias_function(&f.alias)?;
Ok(())
Expand Down

0 comments on commit 0fd74ba

Please sign in to comment.