@@ -47,27 +47,21 @@ int ParseArgs( const std::unordered_map<std::string, runcpp2::OptionInfo>& long
4747 continue ;
4848 }
4949
50- // Checking for options
50+ // Matched long or short options
5151 if (longOptionsMap.count (currentArg) || shortOptionsMap.count (currentArg))
5252 {
5353 currentArgIndex = i;
5454 ssLOG_DEBUG (" currentArgIndex: " << currentArgIndex);
5555 ssLOG_DEBUG (" argv: " << argv[i]);
56-
5756 const runcpp2::OptionInfo& currentInfo = longOptionsMap.count (currentArg) ?
5857 longOptionsMap.at (currentArg) :
5958 shortOptionsMap.at (currentArg);
60-
61- if (currentInfo.HasValue )
62- {
59+ if (currentInfo.ValueExists )
6360 optionForCapturingValue = currentInfo.Option ;
64- continue ;
65- }
6661 else
67- {
6862 outOptions[currentInfo.Option ] = " " ;
69- continue ;
70- }
63+
64+ continue ;
7165 }
7266 else if (!currentArg.empty () && currentArg[0 ] == ' -' )
7367 {
@@ -174,11 +168,11 @@ int main(int argc, char* argv[])
174168 int currentArgIndex = 0 ;
175169 std::unordered_map<runcpp2::CmdOptions, std::string> currentOptions;
176170 {
177- static_assert (static_cast <int >(runcpp2::CmdOptions::COUNT) == 17 , " Update this" );
171+ static_assert (static_cast <int >(runcpp2::CmdOptions::COUNT) == 19 , " Update this" );
178172 std::unordered_map<std::string, runcpp2::OptionInfo> longOptionsMap =
179173 {
180174 {
181- " --reset-cache " ,
175+ " --rebuild " ,
182176 runcpp2::OptionInfo (runcpp2::CmdOptions::RESET_CACHE, false )
183177 },
184178 {
@@ -217,6 +211,10 @@ int main(int argc, char* argv[])
217211 " --build" ,
218212 runcpp2::OptionInfo (runcpp2::CmdOptions::BUILD, false )
219213 },
214+ {
215+ " --output" ,
216+ runcpp2::OptionInfo (runcpp2::CmdOptions::OUTPUT, true )
217+ },
220218 {
221219 " --version" ,
222220 runcpp2::OptionInfo (runcpp2::CmdOptions::VERSION, false )
@@ -234,19 +232,23 @@ int main(int argc, char* argv[])
234232 runcpp2::OptionInfo (runcpp2::CmdOptions::CLEANUP, false )
235233 },
236234 {
237- " --build- source-only" ,
235+ " --source-only" ,
238236 runcpp2::OptionInfo (runcpp2::CmdOptions::BUILD_SOURCE_ONLY, false )
239237 },
240238 {
241239 " --jobs" ,
242240 runcpp2::OptionInfo (runcpp2::CmdOptions::THREADS, true )
243241 },
242+ {
243+ " --tutorial" ,
244+ runcpp2::OptionInfo (runcpp2::CmdOptions::TUTORIAL, false )
245+ },
244246 };
245247
246- static_assert (static_cast <int >(runcpp2::CmdOptions::COUNT) == 17 , " Update this" );
248+ static_assert (static_cast <int >(runcpp2::CmdOptions::COUNT) == 19 , " Update this" );
247249 std::unordered_map<std::string, const runcpp2::OptionInfo&> shortOptionsMap =
248250 {
249- {" -rc " , longOptionsMap.at (" --reset-cache " )},
251+ {" -rb " , longOptionsMap.at (" --rebuild " )},
250252 {" -ru" , longOptionsMap.at (" --reset-user-config" )},
251253 {" -e" , longOptionsMap.at (" --executable" )},
252254 {" -h" , longOptionsMap.at (" --help" )},
@@ -256,18 +258,19 @@ int main(int argc, char* argv[])
256258 {" -t" , longOptionsMap.at (" --create-script-template" )},
257259 {" -w" , longOptionsMap.at (" --watch" )},
258260 {" -b" , longOptionsMap.at (" --build" )},
261+ {" -o" , longOptionsMap.at (" --output" )},
259262 {" -v" , longOptionsMap.at (" --version" )},
260263 {" -c" , longOptionsMap.at (" --config" )},
261264 {" -cu" , longOptionsMap.at (" --cleanup" )},
262- {" -s" , longOptionsMap.at (" --build- source-only" )},
265+ {" -s" , longOptionsMap.at (" --source-only" )},
263266 {" -j" , longOptionsMap.at (" --jobs" )},
264267 };
265268
266269 currentArgIndex = ParseArgs (longOptionsMap, shortOptionsMap, currentOptions, argc, argv);
267270
268271 if (currentArgIndex == -1 )
269272 {
270- ssLOG_ERROR (" Invalid option " );
273+ ssLOG_ERROR (" Failed to parse arguments. See --help for details " );
271274 return -1 ;
272275 }
273276
@@ -277,31 +280,31 @@ int main(int argc, char* argv[])
277280 // Help message
278281 if (currentOptions.count (runcpp2::CmdOptions::HELP))
279282 {
280- static_assert (static_cast <int >(runcpp2::CmdOptions::COUNT) == 17 , " Update this" );
283+ static_assert (static_cast <int >(runcpp2::CmdOptions::COUNT) == 19 , " Update this" );
281284 ssLOG_BASE (" Usage: runcpp2 [options] [input_file]" );
282285 ssLOG_BASE (" Options:" );
283286 ssLOG_BASE (" Run/Build:" );
284- ssLOG_BASE (" -b, --[b]uild Build the script and copy output files to the working directory" );
287+ ssLOG_BASE (" -b, --[b]uild Build the script but don't run it" );
288+ ssLOG_BASE (" -o, --[o]utput <Output Dir> Output files to the directory specified, must be used with --build" );
285289 ssLOG_BASE (" -w, --[w]atch Watch script changes and output any compiling errors" );
286290 ssLOG_BASE (" -l, --[l]ocal Build in the current working directory under .runcpp2 directory" );
287291 ssLOG_BASE (" -e, --[e]xecutable Runs as executable instead of shared library" );
288292 ssLOG_BASE (" -c, --[c]onfig <file> Use specified config file instead of default" );
289293 ssLOG_BASE (" -t, --create-script-[t]emplate <file> Creates/prepend runcpp2 script info template" );
290- ssLOG_BASE (" -s, --build- [s]ource-only (Re)Builds source files only without building dependencies." );
294+ ssLOG_BASE (" -s, --[s]ource-only (Re)Builds source files only without building dependencies." );
291295 ssLOG_BASE (" The previous built binaries will be used for dependencies." );
292296 ssLOG_BASE (" Requires dependencies to be built already." );
293297 ssLOG_BASE (" -j, --[j]obs Maximum number of threads running. Defaults to 8" );
294298 ssLOG_BASE (" Reset/Cleanup:" );
295- ssLOG_BASE (" -rc , --[r]eset-[c]ache Deletes compiled source files cache only " );
299+ ssLOG_BASE (" -rb , --[r]e[b]uild Deletes compiled source files cache and rebuild " );
296300 ssLOG_BASE (" -ru, --[r]eset-[u]ser-config Replace current user config with the default one" );
297301 ssLOG_BASE (" -rd, --[r]eset-[d]ependencies <names> Reset dependencies (comma-separated names, or \" all\" for all)" );
298302 ssLOG_BASE (" -cu, --[c]lean[u]p Run cleanup commands and remove build directory" );
299303 ssLOG_BASE (" Settings:" );
300304 ssLOG_BASE (" -sc, --[s]how-[c]onfig-path Show where runcpp2 is reading the config from" );
301305 ssLOG_BASE (" -v, --[v]ersion Show the version of runcpp2" );
302306 ssLOG_BASE (" -h, --[h]elp Show this help message" );
303- ssLOG_BASE (" --log-level <level> Sets the log level (Normal, Info, Debug) for runcpp2." );
304-
307+ ssLOG_BASE (" --log-level <level> Sets the log level (Normal, Info, Debug) for runcpp2" );
305308 return 0 ;
306309 }
307310
@@ -327,6 +330,7 @@ int main(int argc, char* argv[])
327330 }
328331
329332 ssLOG_FUNC_INFO ();
333+ INTERNAL_RUNCPP2_SAFE_START ();
330334
331335 // Show user config path
332336 if (currentOptions.count (runcpp2::CmdOptions::SHOW_USER_CONFIG))
@@ -351,7 +355,7 @@ int main(int argc, char* argv[])
351355 ssLOG_ERROR (" Failed reset user config" );
352356 return -1 ;
353357 }
354- ssLOG_LINE (" User config reset successful" );
358+ ssLOG_BASE (" User config reset successful" );
355359 return 0 ;
356360 }
357361
@@ -363,7 +367,7 @@ int main(int argc, char* argv[])
363367 return -1 ;
364368 else
365369 {
366- ssLOG_LINE (" Script template generated" );
370+ ssLOG_BASE (" Script template generated" );
367371 return 0 ;
368372 }
369373 }
@@ -388,7 +392,7 @@ int main(int argc, char* argv[])
388392 std::vector<std::string> scriptArgs;
389393 if (currentArgIndex >= argc)
390394 {
391- ssLOG_ERROR (" An input file is required" );
395+ ssLOG_ERROR (" An input file is required. See --help for details " );
392396 return 1 ;
393397 }
394398
@@ -412,6 +416,13 @@ int main(int argc, char* argv[])
412416 return -1 ;
413417 }
414418
419+ if ( currentOptions.count (runcpp2::CmdOptions::OUTPUT) > 0 &&
420+ currentOptions.count (runcpp2::CmdOptions::BUILD) == 0 )
421+ {
422+ ssLOG_ERROR (" --build option must be supplied when specifying output directory" );
423+ return -1 ;
424+ }
425+
415426 runcpp2::Data::ScriptInfo parsedScriptInfo;
416427
417428 if (currentOptions.count (runcpp2::CmdOptions::WATCH))
@@ -515,18 +526,24 @@ int main(int argc, char* argv[])
515526 }
516527
517528 std::this_thread::sleep_for (std::chrono::seconds (5 ));
518- }
519- }
529+ } // while(true)
530+ } // if(currentOptions.count(runcpp2::CmdOptions::WATCH))
520531
521532 int result = 0 ;
522533
523534 std::string outputDir;
524- if (currentOptions.count (runcpp2::CmdOptions::BUILD) > 0 )
525- outputDir = ghc::filesystem::current_path ().string ();
535+ if ( currentOptions.count (runcpp2::CmdOptions::BUILD) > 0 &&
536+ currentOptions.count (runcpp2::CmdOptions::OUTPUT) > 0 )
537+ {
538+ auto buildOutputDir = ghc::filesystem::path (currentOptions.at (runcpp2::CmdOptions::OUTPUT));
539+ if (buildOutputDir.is_absolute ())
540+ outputDir = buildOutputDir.string ();
541+ else
542+ outputDir = (ghc::filesystem::current_path () / buildOutputDir).string ();
543+ }
526544
527545 ghc::filesystem::file_time_type finalSourceWriteTime;
528546 ghc::filesystem::file_time_type finalIncludeWriteTime;
529-
530547 if (runcpp2::StartPipeline ( script,
531548 profiles,
532549 preferredProfile,
@@ -542,9 +559,27 @@ int main(int argc, char* argv[])
542559 return -1 ;
543560 }
544561
562+ std::vector<std::string> actions;
563+ if (currentOptions.count (runcpp2::CmdOptions::RESET_CACHE) > 0 )
564+ actions.push_back (" Rebuild" );
545565 if (currentOptions.count (runcpp2::CmdOptions::CLEANUP) > 0 )
546- ssLOG_LINE (" Cleanup successful" );
566+ actions.push_back (" Cleanup" );
567+ if (currentOptions.count (runcpp2::CmdOptions::RESET_DEPENDENCIES) > 0 )
568+ actions.push_back (" Dependencies Reset" );
569+ if (currentOptions.count (runcpp2::CmdOptions::BUILD) > 0 )
570+ actions.push_back (" Build" );
547571
572+ std::string action;
573+ if (!actions.empty ())
574+ {
575+ action = actions.front ();
576+ for (int i = 1 ; i < actions.size (); ++i)
577+ action += " , " + actions[i];
578+
579+ ssLOG_BASE (action << " success" );
580+ }
548581 return result;
582+
583+ INTERNAL_RUNCPP2_SAFE_CATCH_RETURN (-1 );
549584}
550585
0 commit comments