Skip to content

Commit 2196fa8

Browse files
committed
Revived help command & single execution mode
1 parent 10a502e commit 2196fa8

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

src/Options.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,15 @@ namespace CLOptions {
7878
outputDir = std::wstring(args[i].begin(), args[i].end());
7979
}}}
8080
};
81-
82-
void parse(std::vector<std::string>& args)
81+
82+
//Returns: Wether the current command should continue execution. e.g. "help" will return false
83+
bool parse(std::vector<std::string>& args)
8384
{
85+
if (args.size() > 0 && args[0] == "help") {
86+
CLOptions::help();
87+
return false;
88+
}
89+
8490
if (args.size() < 2) {
8591
throw std::exception("Correct syntax is \"<file-path> <language> <options>\"");
8692
}
@@ -95,10 +101,6 @@ namespace CLOptions {
95101
}
96102
} //This might be too hard (Probably need to use IFileDialog (that shit is wack))
97103

98-
if (args[0] == "help") {
99-
help();
100-
}
101-
102104
//Get filepath
103105
r_filePath = args[0];
104106

@@ -132,6 +134,8 @@ namespace CLOptions {
132134
//State errors
133135
if (o_forcePerfection && o_forceThroughErrors) { throw std::exception("-f and -p cannot be set simultaneously"); }
134136
}
137+
138+
return true;
135139
}
136140

137141
std::string filePath()
@@ -166,9 +170,11 @@ namespace CLOptions {
166170
}
167171
void help(std::string arg)
168172
{
173+
fmt::print("Syntax: json2x <file-path> <language> <options>\n");
174+
169175
for (auto& option : commandStringToId)
170176
{
171-
fmt::print(" " + option.second.description + '\n');
177+
fmt::print(option.second.description + '\n');
172178
}
173179
}
174180
}

src/Options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "LangFormat.h"
55

66
namespace CLOptions {
7-
void parse(std::vector<std::string>& args);
7+
bool parse(std::vector<std::string>& args);
88

99
std::string filePath();
1010
LangFormat& langFormat();

src/main.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ int main(int argc, char* argv[]) {
1515
const std::wstring outFileName = L"\\output";
1616
bool running = true;
1717

18-
std::cout << "json2x " << VERSION_MAJOR << "." << VERSION_MINOR << "\n";
19-
2018
while (running)
2119
{
2220
try
@@ -31,14 +29,17 @@ int main(int argc, char* argv[]) {
3129
throw std::exception("Correct syntax is \"json2x <file-path> <language> <options>\"\n");
3230
}
3331

34-
for (int i = 0; i < argc; i++) {
32+
for (int i = 1; i < argc; i++) {
3533
args.push_back(argv[i]);
3634
}
3735

3836
running = false; //Run once
3937
argc = 0; //Prevent args being used again
4038
}
4139
else {
40+
41+
std::cout << "json2x " << VERSION_MAJOR << "." << VERSION_MINOR << " (shell mode) " << "\n";
42+
4243
std::cout << ">> ";
4344

4445
std::string tempInput;
@@ -56,7 +57,9 @@ int main(int argc, char* argv[]) {
5657
}
5758
}
5859

59-
CLOptions::parse(args);
60+
if (CLOptions::parse(args) != true) {
61+
continue;
62+
}
6063
}
6164

6265
//Load JSON file
@@ -73,7 +76,7 @@ int main(int argc, char* argv[]) {
7376
//Construct a code generator object with an indent style (4 spaces) and an initial class name ("MyClass")
7477
CodeGenerator generator(CLOptions::indent(), className);
7578

76-
//Write generated code to a file if no parsing error occured
79+
//Get generated code if no parsing error occured
7780
std::string genOutput = generator.convertJson(json, CLOptions::langFormat());
7881

7982
//Write generated code to file

0 commit comments

Comments
 (0)