From 709defc4f610430596ee6733ca3087bbb36e60cf Mon Sep 17 00:00:00 2001 From: Thraix Date: Thu, 10 Oct 2019 18:53:33 +0200 Subject: [PATCH 1/4] Start implementing conf command --- Makefile | 17 ++++++++++------- src/CLI.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/CLI.h | 7 +++++++ src/Common.h | 3 ++- src/main.cpp | 11 +++++++++-- 5 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 src/CLI.cpp create mode 100644 src/CLI.h diff --git a/Makefile b/Makefile index df24277..441f379 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ MKDIR_P=mkdir -p BIN=bin/ OBJPATH=$(BIN)intermediates INCLUDES= -OBJECTS=$(OBJPATH)/ConfigFile.o $(OBJPATH)/HFileGen.o $(OBJPATH)/IncludeDeps.o $(OBJPATH)/Makefile.o $(OBJPATH)/Utils.o $(OBJPATH)/main.o +OBJECTS=$(OBJPATH)/CLI.o $(OBJPATH)/ConfigFile.o $(OBJPATH)/HFileGen.o $(OBJPATH)/IncludeDeps.o $(OBJPATH)/Makefile.o $(OBJPATH)/Utils.o $(OBJPATH)/main.o CFLAGS=$(INCLUDES) -std=c++17 -c -w -g3 -D_DEBUG LIBDIR= LDFLAGS= @@ -33,21 +33,24 @@ $(OUTPUT): $(OBJECTS) install: all $(info Installing MakeGen to /usr/bin/) @cp $(OUTPUT) /usr/bin/makegen +$(OBJPATH)/CLI.o : src/CLI.cpp src/CLI.h src/Common.h src/ConfigFile.h + $(info -[14%]- $<) + $(CC) $(CFLAGS) -o $@ $< $(OBJPATH)/ConfigFile.o : src/ConfigFile.cpp src/ConfigFile.h src/FileUtils.h src/Common.h src/Utils.h - $(info -[16%]- $<) + $(info -[28%]- $<) $(CC) $(CFLAGS) -o $@ $< $(OBJPATH)/HFileGen.o : src/HFileGen.cpp src/FileUtils.h src/Common.h src/Utils.h src/ConfigFile.h src/HFileGen.h - $(info -[33%]- $<) + $(info -[42%]- $<) $(CC) $(CFLAGS) -o $@ $< $(OBJPATH)/IncludeDeps.o : src/IncludeDeps.cpp src/Common.h src/IncludeDeps.h src/ConfigFile.h src/FileUtils.h src/Utils.h - $(info -[50%]- $<) + $(info -[57%]- $<) $(CC) $(CFLAGS) -o $@ $< $(OBJPATH)/Makefile.o : src/Makefile.cpp src/IncludeDeps.h src/ConfigFile.h src/FileUtils.h src/Common.h src/Utils.h src/Makefile.h - $(info -[66%]- $<) + $(info -[71%]- $<) $(CC) $(CFLAGS) -o $@ $< $(OBJPATH)/Utils.o : src/Utils.cpp src/FileUtils.h src/Common.h src/Utils.h src/ConfigFile.h - $(info -[83%]- $<) + $(info -[85%]- $<) $(CC) $(CFLAGS) -o $@ $< -$(OBJPATH)/main.o : src/main.cpp src/Common.h src/ConfigFile.h src/FileUtils.h src/Utils.h src/HFileGen.h src/Makefile.h src/Timer.h +$(OBJPATH)/main.o : src/main.cpp src/CLI.h src/Common.h src/ConfigFile.h src/FileUtils.h src/Utils.h src/HFileGen.h src/Makefile.h src/Timer.h $(info -[100%]- $<) $(CC) $(CFLAGS) -o $@ $< diff --git a/src/CLI.cpp b/src/CLI.cpp new file mode 100644 index 0000000..8040fe8 --- /dev/null +++ b/src/CLI.cpp @@ -0,0 +1,48 @@ +#include "CLI.h" + +#include "Common.h" +#include "ConfigFile.h" + +void CLI::DisplayCLIHelp() +{ + LOG_INFO("MakeGen conf is used to create, modify and query the makegen.conf file."); + LOG_INFO(""); + LOG_INFO("Usage: makegen conf [] [--help] "); + LOG_INFO(""); + LOG_INFO("Generating config files"); + LOG_INFO(" gen Prompt the user to enter information to create config"); + LOG_INFO(""); + + LOG_INFO("Modifying config settings"); + LOG_INFO(" add Add values to config settings which support multiple arguments"); + LOG_INFO(" remove Remove values to config settings which support multiple"); + LOG_INFO(" arguments"); + LOG_INFO(" set Set value to config settings which support only one argument"); + LOG_INFO(""); + + LOG_INFO("Querying config settings"); + LOG_INFO(" get List all values of the config setting"); + // --------------------------------------------------------------------------------------| +} + +int CLI::Main(int argc, char** argv) +{ + // Do nothing + if(argc < 2 || std::string(argv[1]) == "--help") + { + DisplayCLIHelp(); + return 0; + } + std::string command = argv[1]; + if(command == "gen") + { + ConfigFile::Gen().Save(); + return 0; + } + else + { + LOG_ERROR("Unknown config command: ", command); + return 1; + } + return 0; +} diff --git a/src/CLI.h b/src/CLI.h new file mode 100644 index 0000000..c7c592b --- /dev/null +++ b/src/CLI.h @@ -0,0 +1,7 @@ +#pragma once + +struct CLI +{ + static void DisplayCLIHelp(); + static int Main(int argc, char** argv); +}; diff --git a/src/Common.h b/src/Common.h index cec2180..40eb637 100755 --- a/src/Common.h +++ b/src/Common.h @@ -12,7 +12,7 @@ // Release , should be backwards compatible with any minor version #define MAKEGEN_VERSION_RELEASE 1 // Minor changes, should be compatible with any other minor version with same major and release. -#define MAKEGEN_VERSION_MINOR 7 +#define MAKEGEN_VERSION_MINOR 8 #define MAKEGEN_VERSION ("v" STR(MAKEGEN_VERSION_MAJOR) "." STR(MAKEGEN_VERSION_RELEASE) "." STR(MAKEGEN_VERSION_MINOR)) const static unsigned int FLAG_HELP = BIT(0); @@ -26,6 +26,7 @@ const static unsigned int FLAG_REBUILD = BIT(7); const static unsigned int FLAG_SINGLE_THREAD = BIT(8); const static unsigned int FLAG_DEPENDENCY = BIT(9); const static unsigned int FLAG_SIMPLE = BIT(10); +const static unsigned int FLAG_CLI = BIT(11); #define LOG_INFO(...) Log(__VA_ARGS__); std::cout << std::endl diff --git a/src/main.cpp b/src/main.cpp index a8a5799..465c11e 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,4 @@ +#include "CLI.h" #include "Common.h" #include "ConfigFile.h" #include "FileUtils.h" @@ -22,8 +23,8 @@ void PrintHelp() LOG_INFO(""); LOG_INFO(" Options:"); LOG_INFO(" -h, --help Displays this information"); - LOG_INFO(" --conf Prompt the user to enter information to create config"); - LOG_INFO(" file"); + LOG_INFO(" conf Run config command with given parameters. To see more"); + LOG_INFO(" run makegen conf --help"); LOG_INFO(" -v, --version Displays the version of this program"); LOG_INFO(" -m,-a, make, all Generates a Makefile and runs"); LOG_INFO(" make all"); @@ -55,6 +56,8 @@ void GenMakefile(const ConfigFile& conf, unsigned int flags) unsigned int ReadFlags(int argc, char** argv) { + if(argc >= 2 && std::string(argv[1]) == "conf") + return FLAG_CLI; unsigned int flags = 0; bool make = true; for(int i = 1;i files{}; auto conf = ConfigFile::GetConfigFile(); if(conf) From 17245655d4869e8dbd77c2d68ca9d2803774b509 Mon Sep 17 00:00:00 2001 From: Thraix Date: Thu, 10 Oct 2019 21:36:30 +0200 Subject: [PATCH 2/4] Add all config cli commands --- Makefile | 10 +- makegen.conf | 11 +- src/CLI.cpp | 48 ------ src/CLI.h | 7 - src/Common.h | 4 +- src/ConfigCLI.cpp | 362 +++++++++++++++++++++++++++++++++++++++++++++ src/ConfigCLI.h | 27 ++++ src/ConfigFile.cpp | 4 +- src/main.cpp | 19 +-- 9 files changed, 408 insertions(+), 84 deletions(-) delete mode 100644 src/CLI.cpp delete mode 100644 src/CLI.h create mode 100644 src/ConfigCLI.cpp create mode 100644 src/ConfigCLI.h diff --git a/Makefile b/Makefile index 441f379..75efbf5 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# This Makefile was generated using MakeGen v1.1.7 made by Tim HÃ¥kansson +# This Makefile was generated using MakeGen v1.1.8 made by Tim HÃ¥kansson # and is licensed under MIT. Full source of the project can be found at # https://github.com/Thraix/MakeGen CC=@g++ @@ -7,7 +7,7 @@ MKDIR_P=mkdir -p BIN=bin/ OBJPATH=$(BIN)intermediates INCLUDES= -OBJECTS=$(OBJPATH)/CLI.o $(OBJPATH)/ConfigFile.o $(OBJPATH)/HFileGen.o $(OBJPATH)/IncludeDeps.o $(OBJPATH)/Makefile.o $(OBJPATH)/Utils.o $(OBJPATH)/main.o +OBJECTS=$(OBJPATH)/ConfigCLI.o $(OBJPATH)/ConfigFile.o $(OBJPATH)/HFileGen.o $(OBJPATH)/IncludeDeps.o $(OBJPATH)/Makefile.o $(OBJPATH)/Utils.o $(OBJPATH)/main.o CFLAGS=$(INCLUDES) -std=c++17 -c -w -g3 -D_DEBUG LIBDIR= LDFLAGS= @@ -31,9 +31,9 @@ $(OUTPUT): $(OBJECTS) $(info Generating output file) $(CO) $(OUTPUT) $(OBJECTS) $(LDFLAGS) $(LIBS) install: all - $(info Installing MakeGen to /usr/bin/) + $(info Installing Testing space to /usr/bin/) @cp $(OUTPUT) /usr/bin/makegen -$(OBJPATH)/CLI.o : src/CLI.cpp src/CLI.h src/Common.h src/ConfigFile.h +$(OBJPATH)/ConfigCLI.o : src/ConfigCLI.cpp src/Common.h src/ConfigCLI.h src/ConfigFile.h $(info -[14%]- $<) $(CC) $(CFLAGS) -o $@ $< $(OBJPATH)/ConfigFile.o : src/ConfigFile.cpp src/ConfigFile.h src/FileUtils.h src/Common.h src/Utils.h @@ -51,6 +51,6 @@ $(OBJPATH)/Makefile.o : src/Makefile.cpp src/IncludeDeps.h src/ConfigFile.h src/ $(OBJPATH)/Utils.o : src/Utils.cpp src/FileUtils.h src/Common.h src/Utils.h src/ConfigFile.h $(info -[85%]- $<) $(CC) $(CFLAGS) -o $@ $< -$(OBJPATH)/main.o : src/main.cpp src/CLI.h src/Common.h src/ConfigFile.h src/FileUtils.h src/Utils.h src/HFileGen.h src/Makefile.h src/Timer.h +$(OBJPATH)/main.o : src/main.cpp src/Common.h src/ConfigCLI.h src/ConfigFile.h src/FileUtils.h src/Utils.h src/HFileGen.h src/Makefile.h src/Timer.h $(info -[100%]- $<) $(CC) $(CFLAGS) -o $@ $< diff --git a/makegen.conf b/makegen.conf index 89366d7..c4c50a8 100644 --- a/makegen.conf +++ b/makegen.conf @@ -1,18 +1,19 @@ #libs #libdirs #includedirs -#srcdir -src #defines _DEBUG #compileflags +#dependencies +#srcdir +src/ #outputdir bin #projectname -MakeGen +Testing space #outputname makegen #executable true -#dependencies - +#generatehfile +false diff --git a/src/CLI.cpp b/src/CLI.cpp deleted file mode 100644 index 8040fe8..0000000 --- a/src/CLI.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "CLI.h" - -#include "Common.h" -#include "ConfigFile.h" - -void CLI::DisplayCLIHelp() -{ - LOG_INFO("MakeGen conf is used to create, modify and query the makegen.conf file."); - LOG_INFO(""); - LOG_INFO("Usage: makegen conf [] [--help] "); - LOG_INFO(""); - LOG_INFO("Generating config files"); - LOG_INFO(" gen Prompt the user to enter information to create config"); - LOG_INFO(""); - - LOG_INFO("Modifying config settings"); - LOG_INFO(" add Add values to config settings which support multiple arguments"); - LOG_INFO(" remove Remove values to config settings which support multiple"); - LOG_INFO(" arguments"); - LOG_INFO(" set Set value to config settings which support only one argument"); - LOG_INFO(""); - - LOG_INFO("Querying config settings"); - LOG_INFO(" get List all values of the config setting"); - // --------------------------------------------------------------------------------------| -} - -int CLI::Main(int argc, char** argv) -{ - // Do nothing - if(argc < 2 || std::string(argv[1]) == "--help") - { - DisplayCLIHelp(); - return 0; - } - std::string command = argv[1]; - if(command == "gen") - { - ConfigFile::Gen().Save(); - return 0; - } - else - { - LOG_ERROR("Unknown config command: ", command); - return 1; - } - return 0; -} diff --git a/src/CLI.h b/src/CLI.h deleted file mode 100644 index c7c592b..0000000 --- a/src/CLI.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -struct CLI -{ - static void DisplayCLIHelp(); - static int Main(int argc, char** argv); -}; diff --git a/src/Common.h b/src/Common.h index 40eb637..b9cf4dc 100755 --- a/src/Common.h +++ b/src/Common.h @@ -16,7 +16,7 @@ #define MAKEGEN_VERSION ("v" STR(MAKEGEN_VERSION_MAJOR) "." STR(MAKEGEN_VERSION_RELEASE) "." STR(MAKEGEN_VERSION_MINOR)) const static unsigned int FLAG_HELP = BIT(0); -const static unsigned int FLAG_GEN = BIT(1); +// const static unsigned int FLAG_GEN = BIT(1); const static unsigned int FLAG_VERSION = BIT(2); const static unsigned int FLAG_CLEAN = BIT(3); const static unsigned int FLAG_MAKE = BIT(4); @@ -26,7 +26,7 @@ const static unsigned int FLAG_REBUILD = BIT(7); const static unsigned int FLAG_SINGLE_THREAD = BIT(8); const static unsigned int FLAG_DEPENDENCY = BIT(9); const static unsigned int FLAG_SIMPLE = BIT(10); -const static unsigned int FLAG_CLI = BIT(11); +const static unsigned int FLAG_CONFIG = BIT(11); #define LOG_INFO(...) Log(__VA_ARGS__); std::cout << std::endl diff --git a/src/ConfigCLI.cpp b/src/ConfigCLI.cpp new file mode 100644 index 0000000..6bafe1f --- /dev/null +++ b/src/ConfigCLI.cpp @@ -0,0 +1,362 @@ +#include "ConfigCLI.h" + +#include "Common.h" +#include "ConfigFile.h" + +#include + +void ConfigCLI::DisplayCLIHelp() +{ + LOG_INFO("MakeGen conf is used to create, modify and query the makegen.conf file."); + LOG_INFO(""); + LOG_INFO("Usage: makegen conf [] [--help] "); + LOG_INFO(""); + LOG_INFO("Generating config files"); + LOG_INFO(" gen Prompt the user to enter information to create config"); + LOG_INFO(""); + + LOG_INFO("Modifying config settings"); + LOG_INFO(" add Add values to config settings which support multiple arguments"); + LOG_INFO(" remove Remove values to config settings which support multiple"); + LOG_INFO(" arguments"); + LOG_INFO(" set Set value to config settings which support only one argument"); + LOG_INFO(""); + + LOG_INFO("Querying config settings"); + LOG_INFO(" get Get value of the config setting"); +} + +void ConfigCLI::DisplayGenHelp() +{ + LOG_INFO("Generate a config file from prompts"); + LOG_INFO(""); + LOG_INFO("Usage: makegen conf gen