@@ -9,6 +9,14 @@ namespace commands {
99bool EngineInstallCmd::Exec (const std::string& engine,
1010 const std::string& version,
1111 const std::string& src) {
12+ // Start server if server is not started yet
13+ if (!commands::IsServerAlive (host_, port_)) {
14+ CLI_LOG (" Starting server ..." );
15+ commands::ServerStartCmd ssc;
16+ if (!ssc.Exec (host_, port_)) {
17+ return false ;
18+ }
19+ }
1220 // Handle local install, if fails, fallback to remote install
1321 if (!src.empty ()) {
1422 auto res = engine_service_.UnzipEngine (engine, version, src);
@@ -23,20 +31,12 @@ bool EngineInstallCmd::Exec(const std::string& engine,
2331 }
2432
2533 if (show_menu_) {
26- // Start server if server is not started yet
27- if (!commands::IsServerAlive (host_, port_)) {
28- CLI_LOG (" Starting server ..." );
29- commands::ServerStartCmd ssc;
30- if (!ssc.Exec (host_, port_)) {
31- return false ;
32- }
33- }
34-
3534 DownloadProgress dp;
3635 dp.Connect (host_, port_);
3736 // engine can be small, so need to start ws first
38- auto dp_res = std::async (std::launch::deferred,
39- [&dp, &engine] { return dp.Handle (engine); });
37+ auto dp_res = std::async (std::launch::deferred, [&dp, &engine] {
38+ return dp.Handle (DownloadType::Engine);
39+ });
4040 CLI_LOG (" Validating download items, please wait.." )
4141
4242 auto versions_url = url_parser::Url{
@@ -118,7 +118,7 @@ bool EngineInstallCmd::Exec(const std::string& engine,
118118
119119 bool check_cuda_download = !system_info_utils::GetCudaVersion ().empty ();
120120 if (check_cuda_download) {
121- if (!dp.Handle (" cuda " ))
121+ if (!dp.Handle (DownloadType::CudaToolkit ))
122122 return false ;
123123 }
124124
@@ -130,10 +130,8 @@ bool EngineInstallCmd::Exec(const std::string& engine,
130130 DownloadProgress dp;
131131 dp.Connect (host_, port_);
132132 // engine can be small, so need to start ws first
133- auto dp_res = std::async (std::launch::deferred, [&dp] {
134- return dp.Handle (DownloadType::Engine);
135- });
136- CLI_LOG (" Validating download items, please wait.." )
133+ auto dp_res = std::async (std::launch::deferred,
134+ [&dp] { return dp.Handle (DownloadType::Engine); });
137135
138136 auto install_url = url_parser::Url{
139137 .protocol = " http" ,
@@ -146,12 +144,25 @@ bool EngineInstallCmd::Exec(const std::string& engine,
146144 },
147145 };
148146
147+ if (!version.empty ()) {
148+ install_url.queries = {{" version" , version}};
149+ }
150+
149151 auto response = curl_utils::SimplePostJson (install_url.ToFullPath ());
150152 if (response.has_error ()) {
151- CTL_ERR (response.error ());
153+ // TODO: namh refactor later
154+ Json::Value root;
155+ Json::Reader reader;
156+ if (!reader.parse (response.error (), root)) {
157+ CLI_LOG (response.error ());
158+ return false ;
159+ }
160+ CLI_LOG (root[" message" ].asString ());
152161 return false ;
153162 }
154163
164+ CLI_LOG (" Validating download items, please wait.." )
165+
155166 if (!dp_res.get ())
156167 return false ;
157168
0 commit comments