(functions: &FunctionDispatcher, function_name: Option<&String>, output_format: Option<&ListOutputFormat>)
| 682 | } |
| 683 | |
| 684 | fn list_functions(functions: &FunctionDispatcher, function_name: Option<&String>, output_format: Option<&ListOutputFormat>) { |
| 685 | let mut write_table = false; |
| 686 | let mut table = Table::new(&[ |
| 687 | t!("subcommand.tableHeader_functionCategory").to_string().as_ref(), |
| 688 | t!("subcommand.tableHeader_functionName").to_string().as_ref(), |
| 689 | t!("subcommand.tableHeader_minArgs").to_string().as_ref(), |
| 690 | t!("subcommand.tableHeader_maxArgs").to_string().as_ref(), |
| 691 | t!("subcommand.tableHeader_argTypes").to_string().as_ref(), |
| 692 | t!("subcommand.tableHeader_description").to_string().as_ref(), |
| 693 | ]); |
| 694 | if output_format.is_none() && io::stdout().is_terminal() { |
| 695 | // write as table if format is not specified and interactive |
| 696 | write_table = true; |
| 697 | } |
| 698 | let mut include_separator = false; |
| 699 | let returned_types= [ |
| 700 | (FunctionArgKind::Array, "a"), |
| 701 | (FunctionArgKind::Boolean, "b"), |
| 702 | (FunctionArgKind::Lambda, "l"), |
| 703 | (FunctionArgKind::Number, "n"), |
| 704 | (FunctionArgKind::String, "s"), |
| 705 | (FunctionArgKind::Object, "o"), |
| 706 | ]; |
| 707 | |
| 708 | let asterisks = String::from("*"); |
| 709 | let name = function_name.unwrap_or(&asterisks); |
| 710 | let regex_str = convert_wildcard_to_regex(name); |
| 711 | let mut regex_builder = RegexBuilder::new(®ex_str); |
| 712 | regex_builder.case_insensitive(true); |
| 713 | let Ok(regex) = regex_builder.build() else { |
| 714 | error!("{}: {}", t!("subcommand.invalidFunctionFilter"), regex_str); |
| 715 | exit(EXIT_INVALID_ARGS); |
| 716 | }; |
| 717 | |
| 718 | let mut functions_list = functions.list(); |
| 719 | functions_list.sort(); |
| 720 | for function in functions_list { |
| 721 | if !regex.is_match(&function.name) { |
| 722 | continue; |
| 723 | } |
| 724 | |
| 725 | if write_table { |
| 726 | // construct arg_types from '-' times number of accepted_arg_types |
| 727 | let mut arg_types = "-".repeat(returned_types.len()); |
| 728 | for (i, (arg_type, letter)) in returned_types.iter().enumerate() { |
| 729 | if function.return_types.contains(arg_type) { |
| 730 | arg_types.replace_range(i..=i, letter); |
| 731 | } |
| 732 | } |
| 733 | |
| 734 | let max_args = if function.max_args == usize::MAX { |
| 735 | t!("subcommand.maxInt").to_string() |
| 736 | } else { |
| 737 | function.max_args.to_string() |
| 738 | }; |
| 739 | |
| 740 | table.add_row(vec![ |
| 741 | function.category.iter().map(std::string::ToString::to_string).collect::<Vec<String>>().join(", "), |
no test coverage detected