add check for duplicated env var
This commit is contained in:
parent
b5dd43555a
commit
9b04a44325
2 changed files with 12 additions and 1 deletions
|
@ -1843,7 +1843,7 @@ std::vector<llama_arg> gpt_params_parser_init(gpt_params & params, llama_example
|
||||||
[](gpt_params & params, const std::string & value) {
|
[](gpt_params & params, const std::string & value) {
|
||||||
params.model_alias = value;
|
params.model_alias = value;
|
||||||
}
|
}
|
||||||
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_MODEL"));
|
).set_examples({LLAMA_EXAMPLE_SERVER}));
|
||||||
add_opt(llama_arg(
|
add_opt(llama_arg(
|
||||||
{"-m", "--model"}, "FNAME",
|
{"-m", "--model"}, "FNAME",
|
||||||
ex == LLAMA_EXAMPLE_EXPORT_LORA
|
ex == LLAMA_EXAMPLE_EXPORT_LORA
|
||||||
|
|
|
@ -16,7 +16,9 @@ int main(void) {
|
||||||
try {
|
try {
|
||||||
auto options = gpt_params_parser_init(params, (enum llama_example)ex);
|
auto options = gpt_params_parser_init(params, (enum llama_example)ex);
|
||||||
std::unordered_set<std::string> seen_args;
|
std::unordered_set<std::string> seen_args;
|
||||||
|
std::unordered_set<std::string> seen_env_vars;
|
||||||
for (const auto & opt : options) {
|
for (const auto & opt : options) {
|
||||||
|
// check for args duplications
|
||||||
for (const auto & arg : opt.args) {
|
for (const auto & arg : opt.args) {
|
||||||
if (seen_args.find(arg) == seen_args.end()) {
|
if (seen_args.find(arg) == seen_args.end()) {
|
||||||
seen_args.insert(arg);
|
seen_args.insert(arg);
|
||||||
|
@ -25,6 +27,15 @@ int main(void) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// check for env var duplications
|
||||||
|
if (opt.env) {
|
||||||
|
if (seen_env_vars.find(opt.env) == seen_env_vars.end()) {
|
||||||
|
seen_env_vars.insert(opt.env);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "test-arg-parser: found different handlers for the same env var: %s", opt.env);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (std::exception & e) {
|
} catch (std::exception & e) {
|
||||||
printf("%s\n", e.what());
|
printf("%s\n", e.what());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue