55#include < string>
66#include < vector>
77
8+ // embedded data generated by cmake
9+ extern const char * LICENSES[];
10+
811// visible
912int llama_server (int argc, char ** argv);
1013int llama_cli (int argc, char ** argv);
@@ -17,8 +20,11 @@ int llama_fit_params(int argc, char ** argv);
1720int llama_quantize (int argc, char ** argv);
1821int llama_perplexity (int argc, char ** argv);
1922
23+ static const char * progname;
24+
2025static int help (int argc, char ** argv);
2126static int version (int argc, char ** argv);
27+ static int licenses (int argc, char ** argv);
2228
2329struct command {
2430 const char * name;
@@ -37,26 +43,39 @@ static const command cmds[] = {
3743 {" fit-params" , " Compute parameters to fit a model in device memory" , {}, true , llama_fit_params },
3844 {" quantize" , " Quantize a model" , {}, true , llama_quantize },
3945 {" perplexity" , " Compute model perplexity and KL divergence" , {}, true , llama_perplexity },
40- {" version" , " Show version" , {}, true , version },
41- {" help" , " Show available commands" , {}, true , help },
46+ {" version" , " Show version" , {}, false , version },
47+ {" licenses" , " Show third-party licenses" , {" credits" }, false , licenses },
48+ {" help" , " Show available commands" , {}, false , help },
4249};
4350
4451static int version (int argc, char ** argv) {
4552 printf (" %s\n " , llama_build_info ());
4653 return 0 ;
4754}
4855
56+ static int licenses (int argc, char ** argv) {
57+ for (int i = 0 ; LICENSES[i]; ++i) {
58+ printf (" %s\n " , LICENSES[i]);
59+ }
60+ return 0 ;
61+ }
62+
4963static int help (int argc, char ** argv) {
5064 const bool show_all = argc >= 2 && std::string (argv[1 ]) == " all" ;
5165
52- printf (" Usage: llama <command> [options]\n\n Available commands:\n " );
66+ printf (" Usage: %s <command> [options]\n\n Available commands:\n " , progname );
5367
5468 for (const auto & cmd : cmds) {
5569 if (show_all || !cmd.hidden ) {
5670 printf (" %-15s %s\n " , cmd.name , cmd.desc );
5771 }
5872 }
59- printf (" \n Run 'llama <command> --help' for command-specific usage.\n " );
73+ printf (" \n " );
74+
75+ if (!show_all) {
76+ printf (" Run '%s help all' to show additional commands.\n " , progname);
77+ }
78+ printf (" Run '%s <command> --help' for command-specific usage.\n " , progname);
6079
6180 return 0 ;
6281}
@@ -74,13 +93,12 @@ static bool matches(const std::string & arg, const command & cmd) {
7493}
7594
7695int main (int argc, char ** argv) {
96+ progname = argv[0 ];
7797 const std::string arg = argc >= 2 ? argv[1 ] : " help" ;
7898
7999 for (const auto & cmd : cmds) {
80100 if (matches (arg, cmd)) {
81-
82- // router spawns children through this same binary, it needs the
83- // subcommand to relaunch as 'llama serve' and not bare options
101+ // keep cmd.name so the router's child processes re-invoke correctly
84102#ifdef _WIN32
85103 _putenv_s (" LLAMA_APP_CMD" , cmd.name );
86104#else
0 commit comments