Add all config cli commands
This commit is contained in:
@@ -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
|
# and is licensed under MIT. Full source of the project can be found at
|
||||||
# https://github.com/Thraix/MakeGen
|
# https://github.com/Thraix/MakeGen
|
||||||
CC=@g++
|
CC=@g++
|
||||||
@@ -7,7 +7,7 @@ MKDIR_P=mkdir -p
|
|||||||
BIN=bin/
|
BIN=bin/
|
||||||
OBJPATH=$(BIN)intermediates
|
OBJPATH=$(BIN)intermediates
|
||||||
INCLUDES=
|
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
|
CFLAGS=$(INCLUDES) -std=c++17 -c -w -g3 -D_DEBUG
|
||||||
LIBDIR=
|
LIBDIR=
|
||||||
LDFLAGS=
|
LDFLAGS=
|
||||||
@@ -31,9 +31,9 @@ $(OUTPUT): $(OBJECTS)
|
|||||||
$(info Generating output file)
|
$(info Generating output file)
|
||||||
$(CO) $(OUTPUT) $(OBJECTS) $(LDFLAGS) $(LIBS)
|
$(CO) $(OUTPUT) $(OBJECTS) $(LDFLAGS) $(LIBS)
|
||||||
install: all
|
install: all
|
||||||
$(info Installing MakeGen to /usr/bin/)
|
$(info Installing Testing space to /usr/bin/)
|
||||||
@cp $(OUTPUT) /usr/bin/makegen
|
@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%]- $<)
|
$(info -[14%]- $<)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
$(OBJPATH)/ConfigFile.o : src/ConfigFile.cpp src/ConfigFile.h src/FileUtils.h src/Common.h src/Utils.h
|
$(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
|
$(OBJPATH)/Utils.o : src/Utils.cpp src/FileUtils.h src/Common.h src/Utils.h src/ConfigFile.h
|
||||||
$(info -[85%]- $<)
|
$(info -[85%]- $<)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(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%]- $<)
|
$(info -[100%]- $<)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
|
|||||||
+6
-5
@@ -1,18 +1,19 @@
|
|||||||
#libs
|
#libs
|
||||||
#libdirs
|
#libdirs
|
||||||
#includedirs
|
#includedirs
|
||||||
#srcdir
|
|
||||||
src
|
|
||||||
#defines
|
#defines
|
||||||
_DEBUG
|
_DEBUG
|
||||||
#compileflags
|
#compileflags
|
||||||
|
#dependencies
|
||||||
|
#srcdir
|
||||||
|
src/
|
||||||
#outputdir
|
#outputdir
|
||||||
bin
|
bin
|
||||||
#projectname
|
#projectname
|
||||||
MakeGen
|
Testing space
|
||||||
#outputname
|
#outputname
|
||||||
makegen
|
makegen
|
||||||
#executable
|
#executable
|
||||||
true
|
true
|
||||||
#dependencies
|
#generatehfile
|
||||||
|
false
|
||||||
|
|||||||
-48
@@ -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 <command> [<args>] [--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;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
struct CLI
|
|
||||||
{
|
|
||||||
static void DisplayCLIHelp();
|
|
||||||
static int Main(int argc, char** argv);
|
|
||||||
};
|
|
||||||
+2
-2
@@ -16,7 +16,7 @@
|
|||||||
#define MAKEGEN_VERSION ("v" STR(MAKEGEN_VERSION_MAJOR) "." STR(MAKEGEN_VERSION_RELEASE) "." STR(MAKEGEN_VERSION_MINOR))
|
#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_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_VERSION = BIT(2);
|
||||||
const static unsigned int FLAG_CLEAN = BIT(3);
|
const static unsigned int FLAG_CLEAN = BIT(3);
|
||||||
const static unsigned int FLAG_MAKE = BIT(4);
|
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_SINGLE_THREAD = BIT(8);
|
||||||
const static unsigned int FLAG_DEPENDENCY = BIT(9);
|
const static unsigned int FLAG_DEPENDENCY = BIT(9);
|
||||||
const static unsigned int FLAG_SIMPLE = BIT(10);
|
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
|
#define LOG_INFO(...) Log(__VA_ARGS__); std::cout << std::endl
|
||||||
|
|||||||
@@ -0,0 +1,362 @@
|
|||||||
|
#include "ConfigCLI.h"
|
||||||
|
|
||||||
|
#include "Common.h"
|
||||||
|
#include "ConfigFile.h"
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
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 <command> [<args>] [--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 <option>");
|
||||||
|
LOG_INFO("");
|
||||||
|
LOG_INFO("options:");
|
||||||
|
LOG_INFO(" prompt Prompt the user for all needed settings");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigCLI::DisplayAddHelp()
|
||||||
|
{
|
||||||
|
LOG_INFO("Add values to config settings which support multiple arguments");
|
||||||
|
LOG_INFO("");
|
||||||
|
LOG_INFO("Usage: makegen conf add <setting> <value> [<values>]");
|
||||||
|
LOG_INFO("");
|
||||||
|
LOG_INFO("Valid settings are:");
|
||||||
|
LOG_INFO(" library Library");
|
||||||
|
LOG_INFO(" libdir Library directory");
|
||||||
|
LOG_INFO(" includedir Include directory");
|
||||||
|
LOG_INFO(" define Preprocessor define");
|
||||||
|
LOG_INFO(" cflag g++ compiler flags");
|
||||||
|
LOG_INFO(" dependency Project which current project depends on");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigCLI::DisplayRemoveHelp()
|
||||||
|
{
|
||||||
|
LOG_INFO("Remove values to config settings which support multiple arguments");
|
||||||
|
LOG_INFO("");
|
||||||
|
LOG_INFO("Usage: makegen conf remove <setting> <value> [<values>]");
|
||||||
|
LOG_INFO("");
|
||||||
|
LOG_INFO("Valid settings are:");
|
||||||
|
LOG_INFO(" library Library name");
|
||||||
|
LOG_INFO(" libdir Library directory");
|
||||||
|
LOG_INFO(" includedir Include directory");
|
||||||
|
LOG_INFO(" define Preprocessor define");
|
||||||
|
LOG_INFO(" cflag g++ compiler flags");
|
||||||
|
LOG_INFO(" dependency Project which current project depends on");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigCLI::DisplaySetHelp()
|
||||||
|
{
|
||||||
|
LOG_INFO("Set value to config settings which only support one argument");
|
||||||
|
LOG_INFO("");
|
||||||
|
LOG_INFO("Usage: makegen conf set <setting> <value>");
|
||||||
|
LOG_INFO("");
|
||||||
|
LOG_INFO("Valid string settings are:");
|
||||||
|
LOG_INFO(" outputdir Directory of the compiled output");
|
||||||
|
LOG_INFO(" output Name of the output executable/library");
|
||||||
|
LOG_INFO(" name Name of the project");
|
||||||
|
LOG_INFO(" hfile Name of the generated project h-file");
|
||||||
|
LOG_INFO("");
|
||||||
|
LOG_INFO("Valid boolean settings are:");
|
||||||
|
LOG_INFO(" executable Specifies if the project be compiled as executable or library");
|
||||||
|
LOG_INFO(" shared Specifies if the library should be compiled as shared.");
|
||||||
|
LOG_INFO(" genhfile Specifies if MakeGen should generate a project h-file");
|
||||||
|
LOG_INFO("");
|
||||||
|
LOG_INFO("Boolean values can be set to either true/t/yes/y or false/f/no/n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigCLI::DisplayGetHelp()
|
||||||
|
{
|
||||||
|
LOG_INFO("Get value of the config setting");
|
||||||
|
LOG_INFO("");
|
||||||
|
LOG_INFO("Usage: makegen conf get <setting>");
|
||||||
|
LOG_INFO("");
|
||||||
|
LOG_INFO("Valid settings are:");
|
||||||
|
LOG_INFO(" library Library name");
|
||||||
|
LOG_INFO(" libdir Library directory");
|
||||||
|
LOG_INFO(" includedir Include directory");
|
||||||
|
LOG_INFO(" define Preprocessor define");
|
||||||
|
LOG_INFO(" cflag g++ compiler flags");
|
||||||
|
LOG_INFO(" dependency Project which current project depends on");
|
||||||
|
LOG_INFO(" outputdir Directory of the compiled output");
|
||||||
|
LOG_INFO(" output Name of the output executable/library");
|
||||||
|
LOG_INFO(" name Name of the project");
|
||||||
|
LOG_INFO(" hfile Name of the generated project h-file");
|
||||||
|
LOG_INFO(" executable Specifies if the project be compiled as executable or library");
|
||||||
|
LOG_INFO(" shared Specifies if the library should be compiled as shared.");
|
||||||
|
LOG_INFO(" genhfile Specifies if MakeGen should generate a project h-file");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, std::vector<std::string>*> ConfigCLI::GetSettingVectorMap(ConfigFile& config)
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
{"library",&config.libs},
|
||||||
|
{"libdir",&config.libdirs},
|
||||||
|
{"includedir",&config.includedirs},
|
||||||
|
{"define",&config.defines},
|
||||||
|
{"cflag",&config.flags},
|
||||||
|
{"dependency",&config.dependencies}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::map<std::string, std::string*> ConfigCLI::GetSettingStringMap(ConfigFile& config)
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
{"outputdir", &config.outputdir},
|
||||||
|
{"output", &config.outputname},
|
||||||
|
{"name", &config.projectname},
|
||||||
|
{"hfile", &config.hFile},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, bool*> ConfigCLI::GetSettingBoolMap(ConfigFile& config)
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
{"executable", &config.executable},
|
||||||
|
{"shared", &config.shared},
|
||||||
|
{"genhfile", &config.generateHFile}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
int ConfigCLI::Gen(int argc, char** argv)
|
||||||
|
{
|
||||||
|
if(argc < 2 || std::string(argv[1]) == "--help")
|
||||||
|
{
|
||||||
|
DisplayGenHelp();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(argc < 2)
|
||||||
|
{
|
||||||
|
LOG_ERROR("gen needs exactly one parameters");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
std::string option = argv[1];
|
||||||
|
if(option == "prompt")
|
||||||
|
{
|
||||||
|
ConfigFile::Gen().Save();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG_ERROR("Invalid option: ", option);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int ConfigCLI::Add(int argc, char** argv, ConfigFile& config)
|
||||||
|
{
|
||||||
|
if(argc < 2 || std::string(argv[1]) == "--help")
|
||||||
|
{
|
||||||
|
DisplayAddHelp();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(argc < 3)
|
||||||
|
{
|
||||||
|
LOG_ERROR("add needs at least two parameters");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto settingMap = GetSettingVectorMap(config);
|
||||||
|
auto it = settingMap.find(argv[1]);
|
||||||
|
if(it == settingMap.end())
|
||||||
|
{
|
||||||
|
LOG_ERROR("Invalid setting: ", argv[1]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string>* setting = it->second;
|
||||||
|
std::set<std::string> settingSet{setting->begin(), setting->end()};
|
||||||
|
for(int i = 2; i<argc;++i)
|
||||||
|
{
|
||||||
|
auto res = settingSet.emplace(argv[i]);
|
||||||
|
if(!res.second)
|
||||||
|
{
|
||||||
|
LOG_ERROR("Duplicate value: ", argv[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*setting = {settingSet.begin(), settingSet.end()};
|
||||||
|
|
||||||
|
config.Save();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ConfigCLI::Remove(int argc, char** argv, ConfigFile& config)
|
||||||
|
{
|
||||||
|
if(argc < 2 || std::string(argv[1]) == "--help")
|
||||||
|
{
|
||||||
|
DisplayRemoveHelp();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(argc < 3)
|
||||||
|
{
|
||||||
|
LOG_ERROR("remove needs at least two parameters");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto settingMap = GetSettingVectorMap(config);
|
||||||
|
auto it = settingMap.find(argv[1]);
|
||||||
|
if(it == settingMap.end())
|
||||||
|
{
|
||||||
|
LOG_ERROR("Invalid setting: ", argv[1]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string>* setting = it->second;
|
||||||
|
std::set<std::string> settingSet{setting->begin(), setting->end()};
|
||||||
|
for(int i = 2; i<argc;++i)
|
||||||
|
{
|
||||||
|
auto it = settingSet.find(argv[i]);
|
||||||
|
if(it == settingSet.end())
|
||||||
|
{
|
||||||
|
LOG_ERROR("No such value in setting: ", argv[i]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
settingSet.erase(it);
|
||||||
|
}
|
||||||
|
*setting = {settingSet.begin(), settingSet.end()};
|
||||||
|
|
||||||
|
config.Save();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ConfigCLI::Set(int argc, char** argv, ConfigFile& config)
|
||||||
|
{
|
||||||
|
if(argc < 2 || std::string(argv[1]) == "--help")
|
||||||
|
{
|
||||||
|
DisplaySetHelp();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(argc != 3)
|
||||||
|
{
|
||||||
|
LOG_ERROR("set needs exactly two parameters");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto settingStringMap = GetSettingStringMap(config);
|
||||||
|
auto it1 = settingStringMap.find(argv[1]);
|
||||||
|
if(it1 == settingStringMap.end())
|
||||||
|
{
|
||||||
|
auto settingBoolMap = GetSettingBoolMap(config);
|
||||||
|
auto it2 = settingBoolMap.find(argv[1]);
|
||||||
|
if(it2 == settingBoolMap.end())
|
||||||
|
{
|
||||||
|
LOG_ERROR("Invalid setting: ", argv[1]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
std::string b = argv[2];
|
||||||
|
if(b == "true" || b == "t" || b == "yes" || b == "y")
|
||||||
|
*(it2->second) = true;
|
||||||
|
else if(b == "false" || b == "f" || b == "no" || b == "n")
|
||||||
|
*it2->second = false;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG_ERROR("Invalid boolean value: ", argv[2]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
config.Save();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
*it1->second = argv[2];
|
||||||
|
config.Save();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ConfigCLI::Get(int argc, char** argv, ConfigFile& config)
|
||||||
|
{
|
||||||
|
if(argc < 2 || std::string(argv[1]) == "--help")
|
||||||
|
{
|
||||||
|
DisplayGetHelp();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(argc != 2)
|
||||||
|
{
|
||||||
|
LOG_ERROR("get needs exactly one parameters");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
auto settingVectorMap = GetSettingVectorMap(config);
|
||||||
|
auto itV = settingVectorMap.find(argv[1]);
|
||||||
|
if(itV == settingVectorMap.end())
|
||||||
|
{
|
||||||
|
auto settingStringMap = GetSettingStringMap(config);
|
||||||
|
auto itS = settingStringMap.find(argv[1]);
|
||||||
|
if(itS == settingStringMap.end())
|
||||||
|
{
|
||||||
|
auto settingBoolMap = GetSettingBoolMap(config);
|
||||||
|
auto itB = settingBoolMap.find(argv[1]);
|
||||||
|
if(itB == settingBoolMap.end())
|
||||||
|
{
|
||||||
|
LOG_ERROR("Invalid setting: ", argv[1]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
bool* t = itB->second;
|
||||||
|
LOG_INFO(*itB->second ? "true" : "false");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
LOG_INFO(*itS->second);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
for(auto it = itV->second->begin(); it != itV->second->end(); ++it)
|
||||||
|
{
|
||||||
|
LOG_INFO(*it);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ConfigCLI::Main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
// Do nothing
|
||||||
|
if(argc < 2 || std::string(argv[1]) == "--help")
|
||||||
|
{
|
||||||
|
DisplayCLIHelp();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
std::optional<ConfigFile> config = ConfigFile::GetConfigFile();
|
||||||
|
std::string command = argv[1];
|
||||||
|
if(command == "gen")
|
||||||
|
{
|
||||||
|
return Gen(argc-1, &argv[1]);
|
||||||
|
}
|
||||||
|
else if(config)
|
||||||
|
{
|
||||||
|
if(command == "add")
|
||||||
|
return Add(argc-1, &argv[1], *config);
|
||||||
|
else if(command == "remove")
|
||||||
|
return Remove(argc-1, &argv[1], *config);
|
||||||
|
else if(command == "set")
|
||||||
|
return Set(argc-1, &argv[1], *config);
|
||||||
|
else if(command == "get")
|
||||||
|
return Get(argc-1, &argv[1], *config);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG_ERROR("Unknown config command: ", command);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG_ERROR("There is no config file in the current directory");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ConfigFile.h"
|
||||||
|
|
||||||
|
struct ConfigCLI
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static int Main(int argc, char** argv);
|
||||||
|
private:
|
||||||
|
static void DisplayCLIHelp();
|
||||||
|
static void DisplayGenHelp();
|
||||||
|
static void DisplayAddHelp();
|
||||||
|
static void DisplayRemoveHelp();
|
||||||
|
static void DisplaySetHelp();
|
||||||
|
static void DisplayGetHelp();
|
||||||
|
|
||||||
|
static std::map<std::string, std::vector<std::string>*> GetSettingVectorMap(ConfigFile& config);
|
||||||
|
static std::map<std::string, std::string*> GetSettingStringMap(ConfigFile& config);
|
||||||
|
static std::map<std::string, bool*> GetSettingBoolMap(ConfigFile& config);
|
||||||
|
|
||||||
|
static int Gen(int argc, char** argv);
|
||||||
|
static int Add(int argc, char** argv, ConfigFile& config);
|
||||||
|
static int Remove(int argc, char** argv, ConfigFile& config);
|
||||||
|
static int Set(int argc, char** argv, ConfigFile& config);
|
||||||
|
static int Get(int argc, char** argv, ConfigFile& config);
|
||||||
|
|
||||||
|
};
|
||||||
+2
-2
@@ -234,10 +234,10 @@ ConfigFile ConfigFile::Gen()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
InputBoolean("Should it be compiled as a shared library? (y/n)", conf.shared);
|
InputBoolean("Should it be compiled as a shared library? (y/n)", conf.shared);
|
||||||
InputBoolean("Should it compile a single h file? (y/n):", conf.generateHFile);
|
InputBoolean("Should it compile a project h-file? (y/n):", conf.generateHFile);
|
||||||
if(conf.generateHFile)
|
if(conf.generateHFile)
|
||||||
{
|
{
|
||||||
InputString("Enter the h file name (and path): ", conf.hFile, false, false);
|
InputString("Enter the project h-file name (relative to source directory): ", conf.hFile, false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
InputMultiple("Enter include directory:", conf.includedirs, true);
|
InputMultiple("Enter include directory:", conf.includedirs, true);
|
||||||
|
|||||||
+4
-15
@@ -1,5 +1,5 @@
|
|||||||
#include "CLI.h"
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
|
#include "ConfigCLI.h"
|
||||||
#include "ConfigFile.h"
|
#include "ConfigFile.h"
|
||||||
#include "FileUtils.h"
|
#include "FileUtils.h"
|
||||||
#include "HFileGen.h"
|
#include "HFileGen.h"
|
||||||
@@ -23,8 +23,6 @@ void PrintHelp()
|
|||||||
LOG_INFO("");
|
LOG_INFO("");
|
||||||
LOG_INFO(" Options:");
|
LOG_INFO(" Options:");
|
||||||
LOG_INFO(" -h, --help Displays this information");
|
LOG_INFO(" -h, --help Displays this information");
|
||||||
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(" -v, --version Displays the version of this program");
|
||||||
LOG_INFO(" -m,-a, make, all Generates a Makefile and runs");
|
LOG_INFO(" -m,-a, make, all Generates a Makefile and runs");
|
||||||
LOG_INFO(" make all");
|
LOG_INFO(" make all");
|
||||||
@@ -57,7 +55,7 @@ void GenMakefile(const ConfigFile& conf, unsigned int flags)
|
|||||||
unsigned int ReadFlags(int argc, char** argv)
|
unsigned int ReadFlags(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if(argc >= 2 && std::string(argv[1]) == "conf")
|
if(argc >= 2 && std::string(argv[1]) == "conf")
|
||||||
return FLAG_CLI;
|
return FLAG_CONFIG;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
bool make = true;
|
bool make = true;
|
||||||
for(int i = 1;i<argc;i++)
|
for(int i = 1;i<argc;i++)
|
||||||
@@ -69,10 +67,6 @@ unsigned int ReadFlags(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
flags |= FLAG_HELP;
|
flags |= FLAG_HELP;
|
||||||
}
|
}
|
||||||
else if(flag == "--conf")
|
|
||||||
{
|
|
||||||
flags |= FLAG_GEN;
|
|
||||||
}
|
|
||||||
else if(flag == "-v" || flag == "--version")
|
else if(flag == "-v" || flag == "--version")
|
||||||
{
|
{
|
||||||
flags |= FLAG_VERSION;
|
flags |= FLAG_VERSION;
|
||||||
@@ -180,14 +174,9 @@ int main(int argc, char** argv)
|
|||||||
LOG_INFO("MakeGen ",MAKEGEN_VERSION);
|
LOG_INFO("MakeGen ",MAKEGEN_VERSION);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(flags & FLAG_GEN)
|
if(flags & FLAG_CONFIG)
|
||||||
{
|
{
|
||||||
ConfigFile::Gen().Save();
|
return ConfigCLI::Main(argc-1, &argv[1]);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if(flags & FLAG_CLI)
|
|
||||||
{
|
|
||||||
return CLI::Main(argc-1, &argv[1]);
|
|
||||||
}
|
}
|
||||||
std::map<std::string, ConfigFile> files{};
|
std::map<std::string, ConfigFile> files{};
|
||||||
auto conf = ConfigFile::GetConfigFile();
|
auto conf = ConfigFile::GetConfigFile();
|
||||||
|
|||||||
Reference in New Issue
Block a user