|
13 | 13 | #include <metacallcli/tokenizer.hpp> |
14 | 14 |
|
15 | 15 | #include <algorithm> |
| 16 | +#include <filesystem> |
16 | 17 | #include <functional> |
17 | 18 | #include <iostream> |
18 | 19 |
|
@@ -621,7 +622,7 @@ bool application::clear(const std::string &tag, const std::string &script) |
621 | 622 | } |
622 | 623 |
|
623 | 624 | application::application(int argc, char *argv[]) : |
624 | | - exit_condition(false) |
| 625 | + exit_condition(false), plugin_cli_handle(NULL) |
625 | 626 | { |
626 | 627 | /* Set locale */ |
627 | 628 | setlocale(LC_CTYPE, "C"); |
@@ -667,6 +668,33 @@ application::application(int argc, char *argv[]) : |
667 | 668 | std::for_each(&argv[1], argv + /*argc*/ 2, param_it); |
668 | 669 | } |
669 | 670 |
|
| 671 | + /* Get core plugin path and handle in order to load cli plugins */ |
| 672 | + const char *plugin_path = metacall_plugin_path(); |
| 673 | + void *plugin_extension_handle = metacall_plugin_extension(); |
| 674 | + |
| 675 | + /* Define the cli plugin path as string (core plugin path plus cli) */ |
| 676 | + namespace fs = std::filesystem; |
| 677 | + fs::path plugin_cli_path(plugin_path); |
| 678 | + plugin_cli_path /= "cli"; |
| 679 | + std::string plugin_cli_path_str(plugin_cli_path.string()); |
| 680 | + |
| 681 | + /* Load cli plugins into plugin cli handle */ |
| 682 | + void *args[] = { |
| 683 | + metacall_value_create_string(plugin_cli_path_str.c_str(), plugin_cli_path_str.length()), |
| 684 | + metacall_value_create_ptr(&plugin_cli_handle) |
| 685 | + }; |
| 686 | + |
| 687 | + void *ret = metacallhv_s(plugin_extension_handle, "plugin_load_from_path", args, sizeof(args) / sizeof(args[0])); |
| 688 | + |
| 689 | + if (ret == NULL || (ret != NULL && metacall_value_to_int(ret) != 0)) |
| 690 | + { |
| 691 | + std::cout << "Failed to load CLI plugins from folder: " << plugin_cli_path_str << std::endl; |
| 692 | + } |
| 693 | + |
| 694 | + metacall_value_destroy(args[0]); |
| 695 | + metacall_value_destroy(args[1]); |
| 696 | + metacall_value_destroy(ret); |
| 697 | + |
670 | 698 | /* Define available commands */ |
671 | 699 | define("help", &command_cb_help); |
672 | 700 |
|
@@ -833,8 +861,15 @@ void application::command_inspect(const char *str, size_t size, void *allocator) |
833 | 861 | value_array_for_each(v_args_array, [&iterator, &count](void *arg) { |
834 | 862 | void **v_arg_map = metacall_value_to_map(arg); |
835 | 863 | void **v_arg_name_tupla = metacall_value_to_array(v_arg_map[0]); |
| 864 | + std::string parameter_name(metacall_value_to_string(v_arg_name_tupla[1])); |
| 865 | + |
| 866 | + if (parameter_name.empty()) |
| 867 | + { |
| 868 | + parameter_name += "arg"; |
| 869 | + parameter_name += std::to_string(iterator); |
| 870 | + } |
836 | 871 |
|
837 | | - std::cout << metacall_value_to_string(v_arg_name_tupla[1]); |
| 872 | + std::cout << parameter_name; |
838 | 873 |
|
839 | 874 | if (iterator + 1 < count) |
840 | 875 | { |
|
0 commit comments