@@ -65,7 +65,7 @@ constexpr option::Descriptor usage[] = {
6565 { FRAMEWORKS , 0 , " f" , " frameworks" , option::Arg::Optional, " --frameworks, -f \t Apple system frameworks (such as Security,CoreBluetooth), saved in config.make PROJECT_FRAMEWORKS. Empty removes them" },
6666 { SYSTEMLIBS , 0 , " " , " system-libs" , option::Arg::Optional, " --system-libs \t Apple system libraries (such as sqlite3,z = libsqlite3.tbd, libz.tbd), saved in config.make PROJECT_SYSTEM_LIBS. Empty removes them" },
6767
68- { CLEANNAME_DISABLE , 0 , " n" , " cleanname" , option::Arg::Optional, " --cleanname, -f \t cleanname" },
68+ { CLEANNAME_DISABLE , 0 , " n" , " cleanname" , option::Arg::Optional, " --cleanname, -n \t cleanname" },
6969
7070 { DEFINES , 0 , " D" , " defines" , option::Arg::Optional, " --defines, -D \t preprocessor defines list (such as OF_USE_ANGLE=1,MY_FLAG)" },
7171 { POSTBUILD , 0 , " P" , " postbuild" , option::Arg::Optional, " --postbuild, -P \t script to run after the project compiles (Xcode run script / VS post-build event)" },
@@ -472,6 +472,29 @@ int pgMain(int argc, char ** argv) {
472472 // ------------------------------------------------------ parse args
473473 argc -= (argc > 0 );
474474 argv += (argc > 0 ); // skip program name argv[0] if present
475+
476+ // optionparser only takes attached values (-posx, --platforms=osx); join -p osx / --platforms osx,
477+ // but leave the last argument as the project path (-f <path> is an empty -f)
478+ static const std::string valueShort { " paotsmfDPkW" };
479+ static const std::vector<std::string> valueLong { " platforms" , " addons" , " ofPath" , " template" , " source" , " ofmenu" , " frameworks" , " system-libs" , " defines" , " postbuild" , " msys2env" , " emscripten-wasm" , " app-version" , " app-build" };
480+ std::vector<std::string> joinedArgs;
481+ for (int i = 0 ; i < argc; i++) {
482+ std::string a { argv[i] };
483+ bool isValueOption = (a.size () == 2 && a[0 ] == ' -' && valueShort.find (a[1 ]) != std::string::npos)
484+ || (a.rfind (" --" , 0 ) == 0 && std::find (valueLong.begin (), valueLong.end (), a.substr (2 )) != valueLong.end ());
485+ bool keyword = a == " -m" || a == " --ofmenu" ; // status / update-libs, no project path after it
486+ if (isValueOption && i + 1 < argc && argv[i + 1 ][0 ] != ' -' && (i + 2 < argc || keyword)) {
487+ joinedArgs.emplace_back (a + (a.size () == 2 ? " " : " =" ) + argv[i + 1 ]);
488+ i++;
489+ } else {
490+ joinedArgs.emplace_back (a);
491+ }
492+ }
493+ std::vector<char *> joinedArgv;
494+ for (auto & a : joinedArgs) joinedArgv.emplace_back (a.data ());
495+ argc = (int )joinedArgv.size ();
496+ argv = joinedArgv.data ();
497+
475498 option::Stats stats (usage, argc, argv);
476499 vector<option::Option> options (stats.options_max );
477500 vector<option::Option> buffer (stats.buffer_max );
@@ -679,6 +702,13 @@ int pgMain(int argc, char ** argv) {
679702 if (parse.nonOptionsCount () > 0 ) {
680703 projectName = parse.nonOption (0 );
681704 }
705+ // a value the parser didn't take (e.g. -n osx) would silently become the project path
706+ if (parse.nonOptionsCount () > 1 ) {
707+ std::string extra;
708+ for (int i = 0 ; i < parse.nonOptionsCount (); i++) extra += std::string (i ? " , " : " " ) + parse.nonOption (i);
709+ messageError (" More than one project path: " + extra + " - give option values as -posx / --platforms=osx or -p osx" );
710+ return EXIT_USAGE ;
711+ }
682712
683713 // ------------------------------------------------------ post parse
684714
@@ -738,6 +768,10 @@ int pgMain(int argc, char ** argv) {
738768 messageError ( " Invalid project path: {" + projectPath.string () + " }" );
739769 return EXIT_FAILURE ;
740770 }
771+ if (!getOFRoot ().empty () && fs::weakly_canonical (projectPath) == fs::weakly_canonical (getOFRoot ())) {
772+ messageError (" The project path is the openFrameworks folder: " + projectPath.string ());
773+ return EXIT_USAGE ;
774+ }
741775 // make folder
742776 if (!fs::exists (projectPath)) {
743777 try {
0 commit comments