基本Json格式化。
This commit is contained in:
52
main.cpp
Normal file
52
main.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <CLI11.hpp>
|
||||
#include <consoleapi2.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "formater/fmt.json.h"
|
||||
#include "util/axc.util.h"
|
||||
|
||||
#include <zoost/zoost.h>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
zoostCommon::SetOutputU8();
|
||||
|
||||
if (!AxcUtil::initLogger("aux_cmd.log")) {
|
||||
std::cerr << "Failed to init logger." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
// AxcUtil::getLogger()->info("Starting...");
|
||||
// 中文测试。
|
||||
CLI::App app("A simple command line tool");
|
||||
argv = app.ensure_utf8(argv);
|
||||
|
||||
FormatterArg formatArg;
|
||||
|
||||
try {
|
||||
auto jsonSub = app.add_subcommand("json", "Json Operator.");
|
||||
jsonSub->add_option("-i,--indent", formatArg.indent, "Indent size for json format");
|
||||
jsonSub->add_option("-f,--file", formatArg.file, "format file.")->required()->check(CLI::ExistingFile);
|
||||
app.parse(argc, argv);
|
||||
|
||||
if (jsonSub->parsed()) {
|
||||
JsonFormatter jf;
|
||||
auto content = jf.format(formatArg.file, formatArg);
|
||||
if (content.empty()) {
|
||||
AxcUtil::getLogger()->error("Failed to format json file.");
|
||||
return 1;
|
||||
}
|
||||
if (!jf.save(formatArg.file, content)) {
|
||||
AxcUtil::getLogger()->error("Failed to save json file.");
|
||||
return 1;
|
||||
} else {
|
||||
AxcUtil::getLogger()->info("Json file saved successfully.");
|
||||
}
|
||||
}
|
||||
|
||||
} catch (const CLI::ParseError& e) {
|
||||
return app.exit(e);
|
||||
}
|
||||
|
||||
std::cout << "Hello, world! This is ..." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user