22#include < memory>
33#include < optional>
44#include < string>
5+ #include < unordered_map>
6+ #include " commands/config_get_cmd.h"
7+ #include " commands/config_upd_cmd.h"
58#include " commands/cortex_upd_cmd.h"
69#include " commands/engine_get_cmd.h"
710#include " commands/engine_install_cmd.h"
@@ -31,6 +34,7 @@ constexpr const auto kInferenceGroup = "Inference";
3134constexpr const auto kModelsGroup = " Models" ;
3235constexpr const auto kEngineGroup = " Engines" ;
3336constexpr const auto kSystemGroup = " Server" ;
37+ constexpr const auto kConfigGroup = " Configurations" ;
3438constexpr const auto kSubcommands = " Subcommands" ;
3539} // namespace
3640
@@ -57,6 +61,8 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) {
5761
5862 SetupSystemCommands ();
5963
64+ SetupConfigsCommands ();
65+
6066 app_.add_flag (" --verbose" , log_verbose, " Get verbose logs" );
6167
6268 // Logic is handled in main.cc, just for cli helper command
@@ -301,6 +307,62 @@ void CommandLineParser::SetupModelCommands() {
301307 });
302308}
303309
310+ void CommandLineParser::SetupConfigsCommands () {
311+ auto config_cmd =
312+ app_.add_subcommand (" config" , " Subcommands for managing configurations" );
313+ config_cmd->usage (
314+ " Usage:\n " + commands::GetCortexBinary () +
315+ " config status for listing all API server configuration.\n " +
316+ commands::GetCortexBinary () +
317+ " config --cors [on/off] to toggle CORS.\n " +
318+ commands::GetCortexBinary () +
319+ " config --allowed_origins [comma separated origin] to set a list of "
320+ " allowed origin" );
321+ config_cmd->group (kConfigGroup );
322+ auto config_status_cmd =
323+ config_cmd->add_subcommand (" status" , " Print all configurations" );
324+ config_status_cmd->callback ([this ] {
325+ if (std::exchange (executed_, true ))
326+ return ;
327+ commands::ConfigGetCmd ().Exec (cml_data_.config .apiServerHost ,
328+ std::stoi (cml_data_.config .apiServerPort ));
329+ });
330+
331+ // TODO: this can be improved
332+ std::vector<std::string> avai_opts{" cors" , " allowed_origins" };
333+ std::unordered_map<std::string, std::string> description{
334+ {" cors" , " [on/off] Toggling CORS." },
335+ {" allowed_origins" ,
336+ " Allowed origins for CORS. Comma separated. E.g. "
337+ " http://localhost,https://cortex.so" }};
338+ for (const auto & opt : avai_opts) {
339+ std::string option = " --" + opt;
340+ config_cmd->add_option (option, config_update_opts_[opt], description[opt])
341+ ->expected (0 , 1 )
342+ ->default_str (" *" );
343+ }
344+
345+ config_cmd->callback ([this , config_cmd] {
346+ if (std::exchange (executed_, true ))
347+ return ;
348+
349+ auto is_empty = true ;
350+ for (const auto & [key, value] : config_update_opts_) {
351+ if (!value.empty ()) {
352+ is_empty = false ;
353+ break ;
354+ }
355+ }
356+ if (is_empty) {
357+ CLI_LOG (config_cmd->help ());
358+ return ;
359+ }
360+ commands::ConfigUpdCmd ().Exec (cml_data_.config .apiServerHost ,
361+ std::stoi (cml_data_.config .apiServerPort ),
362+ config_update_opts_);
363+ });
364+ }
365+
304366void CommandLineParser::SetupEngineCommands () {
305367 auto engines_cmd =
306368 app_.add_subcommand (" engines" , " Subcommands for managing engines" );
@@ -339,7 +401,7 @@ void CommandLineParser::SetupEngineCommands() {
339401 CLI_LOG (install_cmd->help ());
340402 }
341403 });
342- for (auto & engine : engine_service_.kSupportEngines ) {
404+ for (const auto & engine : engine_service_.kSupportEngines ) {
343405 std::string engine_name{engine};
344406 EngineInstall (install_cmd, engine_name, cml_data_.engine_version ,
345407 cml_data_.engine_src );
0 commit comments