Skip to content

Commit

Permalink
added lib nlohmann/json - improved its modularity
Browse files Browse the repository at this point in the history
  • Loading branch information
batunpc committed Oct 6, 2022
1 parent 43b6bf9 commit d44061b
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "external/termcolor"]
path = external/termcolor
url = https://github.com/ikalnytskyi/termcolor
[submodule "external/json"]
path = external/json
url = https://github.com/netlify/cmake
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ include(AddGitSubmodule) # This will include cmake module files
# Dependencies
add_git_submodule("external/parser")
add_git_submodule("external/termcolor")
add_git_submodule("external/json")

add_subdirectory(config)
add_subdirectory(src)
Expand Down
1 change: 0 additions & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ add_executable(${PALPATINE_EXE} "main.cpp")
target_link_libraries(${PALPATINE_EXE} PUBLIC
${PALPATINE_LIB}
argparse
termcolor
)
26 changes: 5 additions & 21 deletions app/main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include "Palpatine.h"
#include "config.hpp"
#include "Utils.h"
#include <argparse/argparse.hpp>
#include <iostream>
#include <termcolor/termcolor.hpp>

argparse::ArgumentParser setup_parser() {
argparse::ArgumentParser program("palpatine");
Expand All @@ -19,28 +18,14 @@ argparse::ArgumentParser setup_parser() {
return program;
}

void print_banner() {
std::system("clear");
std::cout << termcolor::on_grey << termcolor::bold << termcolor::white
<< " palpatine " << termcolor::reset << " v" << project_version
<< termcolor::dark << termcolor::reset << termcolor::bold
<< " Made with " << termcolor::red << "" << termcolor::reset
<< " by "
<< "Batuhan Ipci" << termcolor::reset << std::endl;
// description
std::cout << termcolor::dark << project_description << termcolor::reset
<< std::endl;
std::cout << std::endl;
}

int main(int argc, char const *argv[]) {
print_banner();
utils_sdds::print_banner();

auto program = setup_parser();
try {
program.parse_args(argc, argv);
} catch (const std::runtime_error &err) {
std::cerr << termcolor::red << termcolor::bold << err.what() << std::endl
<< termcolor::reset;
utils_sdds::print_error(err);
std::cerr << program;
std::exit(1);
}
Expand All @@ -52,8 +37,7 @@ int main(int argc, char const *argv[]) {
Palpatine palpatine(output, input, style);
palpatine.generate();

std::cout << termcolor::green << "Created at: " << termcolor::reset << output
<< "/dist" << std::endl;
utils_sdds::print_location(output);

return 0;
}
1 change: 1 addition & 0 deletions external/json
Submodule json added at 73af34
8 changes: 7 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
add_library(${PALPATINE_LIB} STATIC Palpatine.cpp File.cpp)
add_library(${PALPATINE_LIB} STATIC
"Palpatine.cpp"
"File.cpp"
"Utils.cpp")

target_include_directories(${PALPATINE_LIB} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR} # same as " ./ " # the header files
${CMAKE_BINARY_DIR}/configured_files/include
)
target_link_libraries(${PALPATINE_LIB} PUBLIC
termcolor
)
3 changes: 3 additions & 0 deletions src/File.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include "File.h"
#include "config.hpp"
#include <fstream>
#include <sstream>
#include <string>
#include <termcolor/termcolor.hpp>
#include <vector>
namespace file_sdds {

std::string read_file(std::string file_name) {
std::string file_str;
std::ifstream file_data(file_name);
Expand Down
30 changes: 30 additions & 0 deletions src/Utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "Utils.h"
#include "config.hpp"
#include <iostream>
#include <termcolor/termcolor.hpp>

namespace utils_sdds {
void print_banner() {
std::system("clear");
std::cout << termcolor::on_grey << termcolor::bold << termcolor::white
<< " palpatine " << termcolor::reset << " v" << project_version
<< termcolor::dark << termcolor::reset << termcolor::bold
<< " Made with " << termcolor::red << "" << termcolor::reset
<< " by "
<< "Batuhan Ipci" << termcolor::reset << std::endl;
// description
std::cout << termcolor::dark << project_description << termcolor::reset
<< std::endl;
std::cout << std::endl;
}

void print_error(const std::runtime_error &err) {
std::cerr << termcolor::red << termcolor::bold << err.what()
<< termcolor::reset << std::endl;
}

void print_location(const std::string &location) {
std::cout << termcolor::green << "Created at: " << termcolor::reset
<< location << "/dist" << std::endl;
}
} // namespace utils_sdds
9 changes: 9 additions & 0 deletions src/Utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once
#include <iostream>

namespace utils_sdds {
void print_banner();
void print_error(const std::runtime_error &err);
void print_location(const std::string &location);

} // namespace utils_sdds

0 comments on commit d44061b

Please sign in to comment.