| #pragma once |
|
|
| #include "common.h" |
|
|
| #include <set> |
| #include <map> |
| #include <string> |
| #include <vector> |
| #include <cstring> |
|
|
| |
| #define COMMON_ARG_PRESET_LOAD_ON_STARTUP "__PRESET_LOAD_ON_STARTUP" |
| #define COMMON_ARG_PRESET_STOP_TIMEOUT "__PRESET_STOP_TIMEOUT" |
|
|
| |
| |
| |
|
|
| struct common_arg { |
| std::set<enum llama_example> examples = {LLAMA_EXAMPLE_COMMON}; |
| std::set<enum llama_example> excludes = {}; |
| std::vector<const char *> args; |
| std::vector<const char *> args_neg; |
| const char * value_hint = nullptr; |
| const char * value_hint_2 = nullptr; |
| const char * env = nullptr; |
| std::string help; |
| bool is_sparam = false; |
| bool is_preset_only = false; |
| void (*handler_void) (common_params & params) = nullptr; |
| void (*handler_string) (common_params & params, const std::string &) = nullptr; |
| void (*handler_str_str)(common_params & params, const std::string &, const std::string &) = nullptr; |
| void (*handler_int) (common_params & params, int) = nullptr; |
| void (*handler_bool) (common_params & params, bool) = nullptr; |
|
|
| common_arg() = default; |
|
|
| common_arg( |
| const std::initializer_list<const char *> & args, |
| const char * value_hint, |
| const std::string & help, |
| void (*handler)(common_params & params, const std::string &) |
| ) : args(args), value_hint(value_hint), help(help), handler_string(handler) {} |
|
|
| common_arg( |
| const std::initializer_list<const char *> & args, |
| const char * value_hint, |
| const std::string & help, |
| void (*handler)(common_params & params, int) |
| ) : args(args), value_hint(value_hint), help(help), handler_int(handler) {} |
|
|
| common_arg( |
| const std::initializer_list<const char *> & args, |
| const std::string & help, |
| void (*handler)(common_params & params) |
| ) : args(args), help(help), handler_void(handler) {} |
|
|
| common_arg( |
| const std::initializer_list<const char *> & args, |
| const std::initializer_list<const char *> & args_neg, |
| const std::string & help, |
| void (*handler)(common_params & params, bool) |
| ) : args(args), args_neg(args_neg), help(help), handler_bool(handler) {} |
|
|
| |
| common_arg( |
| const std::initializer_list<const char *> & args, |
| const char * value_hint, |
| const char * value_hint_2, |
| const std::string & help, |
| void (*handler)(common_params & params, const std::string &, const std::string &) |
| ) : args(args), value_hint(value_hint), value_hint_2(value_hint_2), help(help), handler_str_str(handler) {} |
|
|
| common_arg & set_examples(std::initializer_list<enum llama_example> examples); |
| common_arg & set_excludes(std::initializer_list<enum llama_example> excludes); |
| common_arg & set_env(const char * env); |
| common_arg & set_sparam(); |
| common_arg & set_preset_only(); |
| bool in_example(enum llama_example ex); |
| bool is_exclude(enum llama_example ex); |
| bool get_value_from_env(std::string & output) const; |
| bool has_value_from_env() const; |
| std::string to_string() const; |
|
|
| |
| bool operator<(const common_arg& other) const { |
| if (args.empty() || other.args.empty()) { |
| return false; |
| } |
| return strcmp(args[0], other.args[0]) < 0; |
| } |
| bool operator==(const common_arg& other) const { |
| if (args.empty() || other.args.empty()) { |
| return false; |
| } |
| return strcmp(args[0], other.args[0]) == 0; |
| } |
|
|
| |
| std::vector<std::string> get_args() const; |
| std::vector<std::string> get_env() const; |
| }; |
|
|
| namespace common_arg_utils { |
| bool is_truthy(const std::string & value); |
| bool is_falsey(const std::string & value); |
| bool is_autoy(const std::string & value); |
| } |
|
|
| struct common_params_context { |
| enum llama_example ex = LLAMA_EXAMPLE_COMMON; |
| common_params & params; |
| std::vector<common_arg> options; |
| void(*print_usage)(int, char **) = nullptr; |
| common_params_context(common_params & params) : params(params) {} |
| }; |
|
|
| |
| |
| bool common_params_parse(int argc, char ** argv, common_params & params, llama_example ex, void(*print_usage)(int, char **) = nullptr); |
|
|
| |
| bool common_params_to_map(int argc, char ** argv, llama_example ex, std::map<common_arg, std::string> & out_map); |
|
|
| |
| |
| |
| void common_params_add_preset_options(std::vector<common_arg> & args); |
|
|
| |
| common_params_context common_params_parser_init(common_params & params, llama_example ex, void(*print_usage)(int, char **) = nullptr); |
|
|