From 709defc4f610430596ee6733ca3087bbb36e60cf Mon Sep 17 00:00:00 2001 From: Thraix Date: Thu, 10 Oct 2019 18:53:33 +0200 Subject: [PATCH] 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)