@@ -125,13 +125,14 @@ int main(int argc, const char** argv)
125125 " -u, --unattended" , unattended, " Perform an unattended installation" );
126126
127127#ifndef NDEBUG
128- std::string loadConfFile{};
129- app.add_option (" --test-conf-file" , loadConfFile,
130- " Hook for testing configuration file loading" );
131128
132129 std::string testCommand{};
133- app.add_option (" --test-command" , testCommand,
134- " Run a command for testing purposes" );
130+ app.add_option (" --test" , testCommand,
131+ " Run a command for testing purposes" );
132+
133+ std::string testCommandArgs{};
134+ app.add_option (" --test-args" , testCommandArgs,
135+ " Run a command for testing purposes with arguments" );
135136#endif
136137
137138 CLI11_PARSE (app, argc, argv)
@@ -148,16 +149,6 @@ int main(int argc, const char** argv)
148149 }
149150 }());
150151
151- #ifndef NDEBUG
152- if (!loadConfFile.empty ()) {
153- LOG_INFO (" Loading file {}" , loadConfFile);
154- auto file = cloyster::services::files::KeyFile (loadConfFile);
155- LOG_INFO (" Groups: {}" , fmt::join (file.getGroups (), " ," ));
156- LOG_INFO (" Contents: {}" , file.toData ());
157- return EXIT_SUCCESS;
158- }
159- #endif
160-
161152 if (cloyster::showVersion) {
162153 fmt::print (" {}: Version {}\n " , productName, productVersion);
163154 return EXIT_SUCCESS;
@@ -177,6 +168,11 @@ int main(int argc, const char** argv)
177168
178169 cloyster::checkEffectiveUserId ();
179170
171+ // --test implies --unattended
172+ if (!testCommand.empty ()) {
173+ unattended = true ;
174+ }
175+
180176 if (cloyster::dryRun) {
181177 LOG_INFO (" Dry run enabled." );
182178 } else {
@@ -216,7 +212,7 @@ int main(int argc, const char** argv)
216212 model->printData ();
217213#endif
218214
219- if (cloyster::enableTUI) {
215+ if (cloyster::enableTUI && testCommand. empty () ) {
220216 // Entrypoint; if the view is constructed it will start the TUI.
221217 auto view = std::make_unique<Newt>();
222218 auto presenter
@@ -233,15 +229,28 @@ int main(int argc, const char** argv)
233229 initializeSingletons (std::move (model));
234230
235231#ifndef NDEBUG
236- if (!testCommand.empty ()) {
237- LOG_INFO (" Running test command {}" , testCommand);
238- auto runner = cloyster::Singleton<cloyster::BaseRunner>::get ();
239- runner->checkCommand (testCommand);
240- return EXIT_SUCCESS;
241- }
232+ // Run The Test Commands and exit
233+ if (!testCommand.empty ()) {
234+ LOG_INFO (" Running test command {} {} " , testCommand, testCommandArgs);
235+ auto runner = cloyster::Singleton<cloyster::BaseRunner>::get ();
236+ if (testCommand == " checkCommand" ) {
237+ runner->checkCommand (testCommandArgs);
238+ } else if (testCommand == " createHTTPRepo" ) {
239+ assert (testCommandArgs.size () > 0 );
240+ cloyster::createHTTPRepo (testCommandArgs);
241+ } else if (testCommand == " keyFile" ) {
242+ assert (testCommandArgs.size () > 0 );
243+ LOG_INFO (" Loading file {}" , testCommandArgs);
244+ auto file = cloyster::services::files::KeyFile (testCommandArgs);
245+ LOG_INFO (" Groups: {}" , fmt::join (file.getGroups (), " ," ));
246+ LOG_INFO (" Contents: {}" , file.toData ());
247+ } else {
248+ LOG_ERROR (" Invalid test command {}" , testCommand);
249+ return EXIT_FAILURE;
250+ }
251+ return EXIT_SUCCESS;
252+ }
242253#endif
243-
244-
245254 std::unique_ptr<Execution> executionEngine
246255 = std::make_unique<cloyster::services::Shell>();
247256
0 commit comments