Skip to content

Commit

Permalink
Merge pull request #3 from olokreaz/LOF-1
Browse files Browse the repository at this point in the history
add --help option
  • Loading branch information
olokreaz authored Aug 16, 2024
2 parents 3949c0a + b0f9671 commit 9da4d4b
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 47 deletions.
158 changes: 114 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,122 @@
# Compile Time generator of configs
---
GCT - это генератор CT конфига, тоесть из простого конфига, сгенерируется config.h / config.hpp файл, в котором будет все сгенерированые
---
# CTH++

## Introduction

### What is CTH++

## Usage

```text
Usage: cth++ [options]
Options:
-h, --help - show this message
-f, --file=<file> - input json file
-o, --output=<file> - output file
-w, --working=<dir> - working directory
--std <std> - c++ standard
--cmake-target-current-build <target> - current build target
--global-namespace <name> - 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

#### Usage:
```hjson
{
project: {
name: my_project
version: 1.0.0
type: debug|developing
}
config: {
server: {
log: {
level: {
debug: TRACE
release: WARN
}
}
}
}
"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"
}
}
}
```

```cpp
...
namespace my_project{
namespace project{
constexpr char* name = u8"my_project";
constexpr char* version = u8"1.0.0";
constexpr bool debug = true;
constexpr bool developing = true;
constepxr bool release = false;
constexpr bool production = false;
}
namespacee config {
- 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 {
namespacec log {
constexpr char* level = u8"TRACE";
}
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;
}
}
}
...
```


### reference
- buildroot config(make nconfig)
- linux dialog
```
29 changes: 26 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> Path to the JSON configuration file (default: config.json).\n"
<< "\t-w, --working <path> Set the working directory (default: current directory).\n"
<< "\t-o, --output <path> 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 <name> 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 <cxx_standard> 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 );

Expand Down Expand Up @@ -519,4 +542,4 @@ int main( int argc, char** argv )
}

return 0;
} // namesp
}

0 comments on commit 9da4d4b

Please sign in to comment.