app : allow --version, --licenses & --help (#25054)

Signed-off-by: Adrien Gallouët <angt@huggingface.co>
This commit is contained in:
Adrien Gallouët 2026-06-26 23:18:11 +02:00 committed by GitHub
parent 3fc4e10527
commit 050ee92d04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -50,6 +50,7 @@ struct command {
std::vector<std::string> aliases; std::vector<std::string> aliases;
bool hidden; bool hidden;
int (*func)(int, char **); int (*func)(int, char **);
bool flags = false; // allow --name
}; };
#ifdef LLAMA_INSTALL_BUILD #ifdef LLAMA_INSTALL_BUILD
@ -69,9 +70,9 @@ static const command cmds[] = {
{"fit-params", "Compute parameters to fit a model in device memory", {}, true, llama_fit_params }, {"fit-params", "Compute parameters to fit a model in device memory", {}, true, llama_fit_params },
{"quantize", "Quantize a model", {}, true, llama_quantize }, {"quantize", "Quantize a model", {}, true, llama_quantize },
{"perplexity", "Compute model perplexity and KL divergence", {}, true, llama_perplexity }, {"perplexity", "Compute model perplexity and KL divergence", {}, true, llama_perplexity },
{"version", "Show version", {}, false, version }, {"version", "Show version", {}, false, version, true },
{"licenses", "Show third-party licenses", {"credits"}, false, licenses }, {"licenses", "Show third-party licenses", {"credits"}, false, licenses, true },
{"help", "Show available commands", {}, false, help }, {"help", "Show available commands", {}, false, help, true },
}; };
#undef UPDATE_HIDDEN #undef UPDATE_HIDDEN
@ -108,7 +109,10 @@ static int help(int argc, char ** argv) {
return 0; return 0;
} }
static bool matches(const std::string & arg, const command & cmd) { static bool matches(std::string arg, const command & cmd) {
if (cmd.flags && arg.size() > 2 && arg[0] == '-' && arg[1] == '-') {
arg.erase(0, 2);
}
if (arg == cmd.name) { if (arg == cmd.name) {
return true; return true;
} }