\brief parse the options using Boost Program Options with positional arguments \param argc the number of arguments \param argv the arguments \param parsed_args reference to store parsed arguments \return true if parsing was successful, false otherwise
| 61 | /// \param parsed_args reference to store parsed arguments |
| 62 | /// \return true if parsing was successful, false otherwise |
| 63 | bool parse_options(int argc, char *argv[], program_args_t& parsed_args) { |
| 64 | try { |
| 65 | // Define the command line options |
| 66 | po::options_description general("Allowed options"); |
| 67 | general.add_options() |
| 68 | ("help,h", "Show help message") |
| 69 | ("version,v", "Show version information") |
| 70 | ("pmode", po::value<std::string>(&parsed_args.power_mode)->default_value("performance"), |
| 71 | "Set power mode: powersaver, balanced, performance, turbo") |
| 72 | ("asr,a", po::value<bool>(&parsed_args.asr)->default_value(0), |
| 73 | "If load asr model") |
| 74 | ("embed,e", po::value<bool>(&parsed_args.embed)->default_value(0), |
| 75 | "If load embed model") |
| 76 | ("host", po::value<std::string>(&parsed_args.host)->default_value("127.0.0.1"), |
| 77 | "Set the server address (for serve command)") |
| 78 | ("port,p", po::value<int>(&parsed_args.port)->default_value(-1), |
| 79 | "Set the server port number (for serve command)") |
| 80 | ("force", po::bool_switch(&parsed_args.force_redownload), |
| 81 | "Force re-download even if model exists (for pull command)") |
| 82 | ("filter", po::value<std::string>(&parsed_args.list_filter)->default_value("all"), |
| 83 | "Show models: all | installed | not-installed") |
| 84 | ("quiet", po::bool_switch(&parsed_args.sub_process_mode), |
| 85 | "Quiet mode, for sub-process usages") |
| 86 | ("json,j", po::bool_switch(&parsed_args.json_output), |
| 87 | "Output in JSON format (for list, validate, version commands)") |
| 88 | ("ctx-len,c", po::value<int>(&parsed_args.ctx_length)->default_value(-1), |
| 89 | "Set context length") |
| 90 | ("prefill-chunk-len,pcl", po::value<int>(&parsed_args.prefill_chunk_len)->default_value(-1), |
| 91 | "Set prefill chunk length") |
| 92 | ("img-pre-resize,r", po::value<int>(&parsed_args.img_pre_resize)->default_value(2), |
| 93 | "Pre-resize the image, 0: original size, 1: height = 480, 2: height = 720, 3: height = 1080, 4: height = 1440") |
| 94 | ("socket,s", po::value<size_t>(&parsed_args.max_socket_connections)->default_value(10), |
| 95 | "Set the maximum number of socket connections allowed (for serve command)") |
| 96 | ("q-len,q", po::value<size_t>(&parsed_args.max_npu_queue)->default_value(10), |
| 97 | "Set number of max npu queue length (for serve command)") |
| 98 | ("cors", po::value<bool>(&parsed_args.cors)->default_value(1), |
| 99 | "Enable or disable Cross-Origin Resource Sharing (CORS) (for serve command)") |
| 100 | ("preemption", po::value<bool>(&parsed_args.preemption)->default_value(false), |
| 101 | "Enable preemption") |
| 102 | ("prompt,i", po::value<std::string>(&parsed_args.input_file_name)->default_value(""), |
| 103 | "Direct file input"); |
| 104 | |
| 105 | // Define positional arguments |
| 106 | po::positional_options_description pos_desc; |
| 107 | pos_desc.add("command", 1); |
| 108 | pos_desc.add("model_tag", 1); |
| 109 | |
| 110 | // Define hidden options for positional arguments |
| 111 | po::options_description hidden("Hidden options"); |
| 112 | hidden.add_options() |
| 113 | ("command", po::value<std::string>(&parsed_args.command), "Command to execute") |
| 114 | ("model_tag", po::value<std::string>(&parsed_args.model_tag), "Model tag"); |
| 115 | |
| 116 | // Combine all options |
| 117 | po::options_description all_options; |
| 118 | all_options.add(general).add(hidden); |
| 119 | |
| 120 | // Parse command line |