From a19c6d569b37a35e26bc0cdd8a20daf3960e96e5 Mon Sep 17 00:00:00 2001 From: "D.musique" Date: Thu, 8 May 2025 08:41:50 +0200 Subject: [PATCH] Add CLI options --- src/rguilayout.c | 75 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 66 insertions(+), 9 deletions(-) diff --git a/src/rguilayout.c b/src/rguilayout.c index 0de2121..bef2def 100644 --- a/src/rguilayout.c +++ b/src/rguilayout.c @@ -3523,6 +3523,13 @@ static void ShowCommandLineInfo(void) printf(" Supported extensions: .c, .h\n"); printf(" -t, --template : Define code template for output.\n"); printf(" Supported extensions: .c, .h\n\n"); + printf(" -n, --name : Define the output name.\n"); + printf(" -v, --version : Define the version.\n"); + printf(" -c, --company : Define the company.\n"); + printf(" -d, --description : Define the description.\n"); + printf(" --no-anchors : Do not export anchors.\n"); + printf(" --rectangles : Export rectangles.\n"); + printf(" --no-comments : Do not export full comments.\n"); printf("\nEXAMPLES:\n\n"); printf(" > rguilayout --input mytool.rgl --output mytools.h\n"); @@ -3538,6 +3545,14 @@ static void ProcessCommandLine(int argc, char *argv[]) //int outputFormat = 0; // Supported output formats + const char *cliName = NULL; + const char *cliVersion = NULL; + const char *cliCompany = NULL; + const char *cliDescription = NULL; + bool cliNoAnchors = false; + bool cliRecs = false; + bool cliNoComments = false; + // Process command line arguments for (int i = 1; i < argc; i++) { @@ -3590,8 +3605,50 @@ static void ProcessCommandLine(int argc, char *argv[]) } else LOG("WARNING: No template file provided\n"); } - - // TODO: CLI: Support codegen options: exportAnchors, defineRecs, fullComments... + else if ((strcmp(argv[i], "-n") == 0) || (strcmp(argv[i], "--name") == 0)) + { + if (((i + 1) < argc) && (argv[i + 1][0] != '-')) + { + cliName = argv[i + 1]; + i++; + } + } + else if ((strcmp(argv[i], "-v") == 0) || (strcmp(argv[i], "--version") == 0)) + { + if (((i + 1) < argc) && (argv[i + 1][0] != '-')) + { + cliVersion = argv[i + 1]; + i++; + } + } + else if ((strcmp(argv[i], "-c") == 0) || (strcmp(argv[i], "--company") == 0)) + { + if (((i + 1) < argc) && (argv[i + 1][0] != '-')) + { + cliCompany = argv[i + 1]; + i++; + } + } + else if ((strcmp(argv[i], "-d") == 0) || (strcmp(argv[i], "--description") == 0)) + { + if (((i + 1) < argc) && (argv[i + 1][0] != '-')) + { + cliDescription = argv[i + 1]; + i++; + } + } + else if ((strcmp(argv[i], "--no-anchors") == 0)) + { + cliNoAnchors = true; + } + else if ((strcmp(argv[i], "--rectangles") == 0)) + { + cliRecs = true; + } + else if ((strcmp(argv[i], "--no-comments") == 0)) + { + cliNoComments = true; + } } // Process input file @@ -3608,13 +3665,13 @@ static void ProcessCommandLine(int argc, char *argv[]) GuiLayoutConfig guiConfig = { 0 }; memset(&guiConfig, 0, sizeof(GuiLayoutConfig)); - strcpy(guiConfig.name, "window_codegen"); - strcpy(guiConfig.version, toolVersion); - strcpy(guiConfig.company, "raylib technologies"); - strcpy(guiConfig.description, "tool description"); - guiConfig.exportAnchors = true; - guiConfig.defineRecs = false; - guiConfig.fullComments = true; + strcpy(guiConfig.name, cliName ? cliName : "window_codegen"); + strcpy(guiConfig.version, cliVersion ? cliVersion : toolVersion); + strcpy(guiConfig.company, cliCompany ? cliCompany : "raylib technologies"); + strcpy(guiConfig.description, cliDescription ? cliDescription : "tool description"); + guiConfig.exportAnchors = !cliNoAnchors; + guiConfig.defineRecs = cliRecs; + guiConfig.fullComments = !cliNoComments; // Generate C code for gui layout->controls char *guiTemplateCustom = NULL;