Skip to content

Commit 9da4d4b

Browse files
authored
Merge pull request #3 from olokreaz/LOF-1
add --help option
2 parents 3949c0a + b0f9671 commit 9da4d4b

File tree

2 files changed

+140
-47
lines changed

2 files changed

+140
-47
lines changed

README.md

Lines changed: 114 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,122 @@
1-
# Compile Time generator of configs
2-
---
3-
GCT - это генератор CT конфига, тоесть из простого конфига, сгенерируется config.h / config.hpp файл, в котором будет все сгенерированые
4-
---
1+
# CTH++
2+
3+
## Introduction
4+
5+
### What is CTH++
6+
7+
## Usage
8+
9+
```text
10+
Usage: cth++ [options]
11+
Options:
12+
-h, --help - show this message
13+
-f, --file=<file> - input json file
14+
-o, --output=<file> - output file
15+
-w, --working=<dir> - working directory
16+
--std <std> - c++ standard
17+
--cmake-target-current-build <target> - current build target
18+
--global-namespace <name> - global namespace
19+
--debug - debug mode
20+
--release - release mode
21+
--development - development mode
22+
--production - production mode
23+
```
24+
25+
# Example
26+
27+
```shell
28+
$ cth++ -f=config.json -o=config.h
29+
```
30+
31+
- config.json
32+
33+
```json
534

6-
#### Usage:
7-
```hjson
835
{
9-
project: {
10-
name: my_project
11-
version: 1.0.0
12-
type: debug|developing
13-
}
14-
config: {
15-
server: {
16-
log: {
17-
level: {
18-
debug: TRACE
19-
release: WARN
20-
}
21-
}
22-
}
23-
}
36+
"project": {
37+
"name": "Example",
38+
"desc": "Example Example Example ",
39+
"version": "1.1.1",
40+
"debug": true,
41+
"dev": true,
42+
"output-path": "path/to/output",
43+
"project-dir": "path/to/project/dir"
44+
},
45+
"config": {
46+
"client": {
47+
"port": 52485,
48+
"host": "localhost"
49+
},
50+
"server": {
51+
"port": 2000,
52+
"host": "localhost",
53+
"options": {
54+
"max-connections": 10,
55+
"offline": false,
56+
"debug": {
57+
"max-connections": 5
58+
}
59+
}
60+
},
61+
"master": {
62+
"port": 2000,
63+
"host": "localhost"
64+
}
65+
}
2466
}
2567
```
2668

27-
```cpp
28-
...
29-
namespace my_project{
30-
namespace project{
31-
constexpr char* name = u8"my_project";
32-
constexpr char* version = u8"1.0.0";
33-
constexpr bool debug = true;
34-
constexpr bool developing = true;
35-
constepxr bool release = false;
36-
constexpr bool production = false;
37-
}
38-
namespacee config {
69+
- config.hpp
70+
71+
```c++
72+
// path/to/output
73+
/*
74+
_____ _
75+
| ____| __ __ __ _ _ __ ___ _ __ | | ___
76+
| _| \ \/ / / _` | | '_ ` _ \ | '_ \ | | / _ \
77+
| |___ > < | (_| | | | | | | | | |_) | | | | __/
78+
|_____| /_/\_\ \__,_| |_| |_| |_| | .__/ |_| \___|
79+
|_|
80+
*/
81+
82+
#pragma once
83+
84+
#define VERSION_PACK(MAJOR, MINOR, PATCH) \
85+
( ( ( MAJOR ) << 16 ) | ( ( MINOR ) << 8 ) | ( PATCH ) )
86+
87+
88+
namespace config {
89+
namespace project {
90+
constexpr char *name = "Example";
91+
constexpr char *description = "Example work with config";
92+
constexpr char *git_hash = "fb3483f";
93+
constexpr unsigned int version = 65536;
94+
constexpr bool debug = true;
95+
constexpr bool release = false;
96+
constexpr bool development = true;
97+
constexpr bool production = false;
98+
constexpr char *target = "";
99+
constexpr char *mode = "development";
100+
constexpr char *type = "debug";
101+
}
102+
namespace client {
103+
constexpr char *host = "localhost";
104+
constexpr unsigned long long port = 52485ULL;
105+
}
106+
namespace master {
107+
constexpr char *host = "localhost";
108+
constexpr unsigned long long port = 2000ULL;
109+
}
39110
namespace server {
40-
namespacec log {
41-
constexpr char* level = u8"TRACE";
42-
}
111+
constexpr char *host = "localhost";
112+
namespace options {
113+
namespace debug {
114+
constexpr unsigned long long max_connections = 5ULL;
115+
}
116+
constexpr unsigned long long max_connections = 10ULL;
117+
constexpr bool offline = false;
118+
}
119+
constexpr unsigned long long port = 2000ULL;
43120
}
44-
}
45121
}
46-
...
47-
```
48-
49-
50-
### reference
51-
- buildroot config(make nconfig)
52-
- linux dialog
122+
```

src/main.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,35 @@ CMRC_DECLARE( fonts );
381381

382382
int main( int argc, char** argv )
383383
{
384+
const argh::parser opt( argc, argv );
385+
386+
if ( opt[ { "--help", "-h" } ] ) {
387+
llvm::outs( ) << "Usage: your_program [OPTIONS]\n"
388+
<< "Options:\n"
389+
<< "\t-h, --help Show this help message and exit.\n"
390+
<< "\t-f, --file <path> Path to the JSON configuration file (default: config.json).\n"
391+
<< "\t-w, --working <path> Set the working directory (default: current directory).\n"
392+
<< "\t-o, --output <path> Set the output path (default: value from JSON config).\n"
393+
<< "\t-dbg, --debug Set build mode to debug (default: based on JSON config).\n"
394+
<< "\t-rel, --release Set build mode to release.\n"
395+
<< "\t-dev, --development Set build mode to development (default: based on JSON config).\n"
396+
<< "\t-prod, --production Set build mode to production.\n"
397+
<< "\t-ns, --global-namespace <name> Set the global namespace name (default: \"config\").\n"
398+
<< "\t--cmake-target-current-build Specify the current build target (e.g., game-client, engine-server).\n"
399+
<< "\t--std <cxx_standard> Specify the C++ standard (default: cxx23).\n"
400+
<< "Description:\n"
401+
<< "This program parses a JSON configuration file, extracts project settings, and generates C++ code with the "
402+
"specified configurations.\n"
403+
<< "Example:\n"
404+
<< "\tyour_program --file my_config.json --debug --global-namespace my_namespace)\n";
405+
406+
return 0;
407+
}
408+
384409
CompilerInstance* ci = createCompilerInstance( );
385410
ASTContext& context = ci->getASTContext( );
386411
TranslationUnitDecl* global_scope = context.getTranslationUnitDecl( );
387412

388-
const argh::parser opt( argc, argv );
389-
390413
// Создание пространства имен
391414
NamespaceDecl* ns_global_config = CreateNamespace( opt( { "-ns", "--global-namespace" }, "config" ).view( ), context, global_scope );
392415

@@ -519,4 +542,4 @@ int main( int argc, char** argv )
519542
}
520543

521544
return 0;
522-
} // namesp
545+
}

0 commit comments

Comments
 (0)