Skip to content

Commit 1133086

Browse files
authored
Fix cmdLine placing projects into oF root with certain params (#693)
* CLI: take option values given as -p osx / --platforms osx, fail on two project paths or the OF folder as the project * Updated cmdLine from 0.119.0 to 0.120.0 and PG GUI from 0.113.0 to 0.114.0
1 parent 76b80a3 commit 1133086

4 files changed

Lines changed: 39 additions & 5 deletions

File tree

‎commandLine/src/defines.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#define OFPROJECTGENERATOR_MAJOR_VERSION "0"
2-
#define OFPROJECTGENERATOR_MINOR_VERSION "119"
2+
#define OFPROJECTGENERATOR_MINOR_VERSION "120"
33
#define OFPROJECTGENERATOR_PATCH_VERSION "0"
44

55
#define PG_VERSION (OFPROJECTGENERATOR_MAJOR_VERSION "." OFPROJECTGENERATOR_MINOR_VERSION "." OFPROJECTGENERATOR_PATCH_VERSION)

‎commandLine/src/main.cpp‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ constexpr option::Descriptor usage[] = {
6565
{ FRAMEWORKS, 0, "f", "frameworks", option::Arg::Optional, " --frameworks, -f \tApple 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 \tApple 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 \tcleanname" },
68+
{ CLEANNAME_DISABLE, 0, "n", "cleanname", option::Arg::Optional, " --cleanname, -n \tcleanname" },
6969

7070
{ DEFINES, 0, "D", "defines", option::Arg::Optional, " --defines, -D \tpreprocessor defines list (such as OF_USE_ANGLE=1,MY_FLAG)" },
7171
{ POSTBUILD, 0, "P", "postbuild", option::Arg::Optional, " --postbuild, -P \tscript 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 {

‎frontend/npm-shrinkwrap.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎frontend/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "projectGenerator",
33
"productName": "projectGenerator",
4-
"version": "0.113.0",
4+
"version": "0.114.0",
55
"description": "Build electron GUI openFrameworks projectGenerator",
66
"license": "MIT",
77
"main": "index.js",

0 commit comments

Comments
 (0)