From 8b29433bbf5c34cdcb6b180a08717b4ac3ab36f8 Mon Sep 17 00:00:00 2001 From: olokreaz Date: Fri, 16 Aug 2024 17:06:57 +0300 Subject: [PATCH] add --help option add ReadnMe.md --- README.md | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 29 ++++++++++-- 2 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..ecaa2ab --- /dev/null +++ b/README.md @@ -0,0 +1,122 @@ +# CTH++ + +## Introduction + +### What is CTH++ + +## Usage + +```text +Usage: cth++ [options] +Options: + -h, --help - show this message + -f, --file= - input json file + -o, --output= - output file + -w, --working= - working directory + --std - c++ standard + --cmake-target-current-build - current build target + --global-namespace - global namespace + --debug - debug mode + --release - release mode + --development - development mode + --production - production mode +``` + +# Example + +```shell +$ cth++ -f=config.json -o=config.h +``` + +- config.json + +```json + +{ + "project": { + "name": "Example", + "desc": "Example Example Example ", + "version": "1.1.1", + "debug": true, + "dev": true, + "output-path": "path/to/output", + "project-dir": "path/to/project/dir" + }, + "config": { + "client": { + "port": 52485, + "host": "localhost" + }, + "server": { + "port": 2000, + "host": "localhost", + "options": { + "max-connections": 10, + "offline": false, + "debug": { + "max-connections": 5 + } + } + }, + "master": { + "port": 2000, + "host": "localhost" + } + } +} +``` + +- config.hpp + +```c++ +// path/to/output +/* + _____ _ + | ____| __ __ __ _ _ __ ___ _ __ | | ___ + | _| \ \/ / / _` | | '_ ` _ \ | '_ \ | | / _ \ + | |___ > < | (_| | | | | | | | | |_) | | | | __/ + |_____| /_/\_\ \__,_| |_| |_| |_| | .__/ |_| \___| + |_| +*/ + +#pragma once + +#define VERSION_PACK(MAJOR, MINOR, PATCH) \ + ( ( ( MAJOR ) << 16 ) | ( ( MINOR ) << 8 ) | ( PATCH ) ) + + +namespace config { + namespace project { + constexpr char *name = "Example"; + constexpr char *description = "Example work with config"; + constexpr char *git_hash = "fb3483f"; + constexpr unsigned int version = 65536; + constexpr bool debug = true; + constexpr bool release = false; + constexpr bool development = true; + constexpr bool production = false; + constexpr char *target = ""; + constexpr char *mode = "development"; + constexpr char *type = "debug"; + } + namespace client { + constexpr char *host = "localhost"; + constexpr unsigned long long port = 52485ULL; + } + namespace master { + constexpr char *host = "localhost"; + constexpr unsigned long long port = 2000ULL; + } + namespace server { + constexpr char *host = "localhost"; + namespace options { + namespace debug { + constexpr unsigned long long max_connections = 5ULL; + } + constexpr unsigned long long max_connections = 10ULL; + constexpr bool offline = false; + } + constexpr unsigned long long port = 2000ULL; + } +} +``` diff --git a/src/main.cpp b/src/main.cpp index a622b9c..ac7e0c2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -381,12 +381,35 @@ CMRC_DECLARE( fonts ); int main( int argc, char** argv ) { + const argh::parser opt( argc, argv ); + + if ( opt[ { "--help", "-h" } ] ) { + llvm::outs( ) << "Usage: your_program [OPTIONS]\n" + << "Options:\n" + << "\t-h, --help Show this help message and exit.\n" + << "\t-f, --file Path to the JSON configuration file (default: config.json).\n" + << "\t-w, --working Set the working directory (default: current directory).\n" + << "\t-o, --output Set the output path (default: value from JSON config).\n" + << "\t-dbg, --debug Set build mode to debug (default: based on JSON config).\n" + << "\t-rel, --release Set build mode to release.\n" + << "\t-dev, --development Set build mode to development (default: based on JSON config).\n" + << "\t-prod, --production Set build mode to production.\n" + << "\t-ns, --global-namespace Set the global namespace name (default: \"config\").\n" + << "\t--cmake-target-current-build Specify the current build target (e.g., game-client, engine-server).\n" + << "\t--std Specify the C++ standard (default: cxx23).\n" + << "Description:\n" + << "This program parses a JSON configuration file, extracts project settings, and generates C++ code with the " + "specified configurations.\n" + << "Example:\n" + << "\tyour_program --file my_config.json --debug --global-namespace my_namespace)\n"; + + return 0; + } + CompilerInstance* ci = createCompilerInstance( ); ASTContext& context = ci->getASTContext( ); TranslationUnitDecl* global_scope = context.getTranslationUnitDecl( ); - const argh::parser opt( argc, argv ); - // Создание пространства имен NamespaceDecl* ns_global_config = CreateNamespace( opt( { "-ns", "--global-namespace" }, "config" ).view( ), context, global_scope ); @@ -519,4 +542,4 @@ int main( int argc, char** argv ) } return 0; -} // namesp +}