44
55namespace xary ::cli {
66
7- Options ArgumentParser::parse (int argc, char * argv[]) {
8- Options options;
9- if (argc <= 1 ) {
10- options.mode = Mode::Help;
11- return options;
12- }
7+ Options ArgumentParser::parse (int argc, char * argv[]) {
8+ Options options;
9+ if (argc <= 1 ) {
10+ options.mode = Mode::Help;
11+ return options;
12+ }
1313
14- std::vector<std::string> args (argv + 1 , argv + argc);
14+ std::vector<std::string> args (argv + 1 , argv + argc);
1515
16- for (std::size_t i = 0 ; i < args.size (); ++i) {
17- const auto & arg = args[i];
16+ for (std::size_t i = 0 ; i < args.size (); ++i) {
17+ const auto & arg = args[i];
1818
19- if (arg == " -h" || arg == " --help" ) {
20- options.mode = Mode::Help;
21- return options;
22- } else if (arg == " -v" || arg == " --version" ) {
23- options.mode = Mode::Version;
24- return options;
25- } else if (arg == " -e" || arg == " --encode" ) {
26- if (i + 1 < args.size ()) {
27- options.mode = Mode::Encode;
28- options.inputFile = args[++i];
29- } else {
30- options.isValid = false ;
31- options.errorMessage = " Missing input file path for --encode flag." ;
32- return options;
33- }
34- } else if (arg == " -d" || arg == " --decode" ) {
35- if (i + 1 < args.size ()) {
36- options.mode = Mode::Decode;
37- options.inputFile = args[++i];
38- } else {
39- options.isValid = false ;
40- options.errorMessage = " Missing input file path for --decode flag." ;
41- return options;
42- }
43- } else if (arg == " -o" || arg == " --output" ) {
44- if (i + 1 < args.size ()) {
45- options.outputFile = args[++i];
46- } else {
47- options.isValid = false ;
48- options.errorMessage = " Missing output file path for --output flag." ;
49- return options;
50- }
51- } else {
52- options.isValid = false ;
53- options.errorMessage = " Unknown argument or flag: " + arg;
54- return options;
55- }
19+ if (arg == " -h" || arg == " --help" ) {
20+ options.mode = Mode::Help;
21+ return options;
22+ } else if (arg == " -v" || arg == " --version" ) {
23+ options.mode = Mode::Version;
24+ return options;
25+ } else if (arg == " -e" || arg == " --encode" ) {
26+ if (i + 1 < args.size ()) {
27+ options.mode = Mode::Encode;
28+ options.inputFile = args[++i];
29+ } else {
30+ options.isValid = false ;
31+ options.errorMessage = " Missing input file path for --encode flag." ;
32+ return options;
33+ }
34+ } else if (arg == " -d" || arg == " --decode" ) {
35+ if (i + 1 < args.size ()) {
36+ options.mode = Mode::Decode;
37+ options.inputFile = args[++i];
38+ } else {
39+ options.isValid = false ;
40+ options.errorMessage = " Missing input file path for --decode flag." ;
41+ return options;
42+ }
43+ } else if (arg == " -o" || arg == " --output" ) {
44+ if (i + 1 < args.size ()) {
45+ options.outputFile = args[++i];
46+ } else {
47+ options.isValid = false ;
48+ options.errorMessage = " Missing output file path for --output flag." ;
49+ return options;
50+ }
51+ } else if (arg == " -i" || arg == " --inspect" ) {
52+ if (i + 1 < args.size ()) {
53+ options.mode = Mode::Inspect;
54+ options.inputFile = args[++i];
55+ } else {
56+ options.isValid = false ;
57+ options.errorMessage = " Missing target file path for --inspect flag." ;
58+ return options;
59+ }
60+ } else {
61+ options.isValid = false ;
62+ options.errorMessage = " Unknown argument or flag: " + arg;
63+ return options;
5664 }
65+ }
5766
58- return options;
67+ return options;
5968}
6069
6170void ArgumentParser::printHelp () {
62- std::cout << " Usage: xary [OPTIONS]\n\n "
63- << " Options:\n "
64- << " -h, --help Display this help menu and exit\n "
65- << " -v, --version Display engine version\n "
66- << " -e, --encode <file> Encode binary file in 64 KB chunks\n "
67- << " -d, --decode <file> Decode binary file in 64 KB chunks\n "
68- << " -o, --output <file> Specify custom output file path\n\n "
69- << " Examples:\n "
70- << " xary --version\n "
71- << " xary -e data.bin\n "
72- << " xary -e data.bin -o encoded.xary\n "
73- << " xary -d encoded.xary -o restored.bin\n " ;
71+ std::cout
72+ << " Usage: xary [OPTIONS]\n\n "
73+ << " Options:\n "
74+ << " -h, --help Display this help menu and exit\n "
75+ << " -v, --version Display engine version\n "
76+ << " -e, --encode <file> Encode binary file in 64 KB chunks\n "
77+ << " -d, --decode <file> Decode binary file in 64 KB chunks\n "
78+ << " -i, --inspect <file> Inspect file magic signature & detect real extension\n "
79+ << " -o, --output <file> Specify custom output file path\n\n "
80+ << " Examples:\n "
81+ << " xary --version\n "
82+ << " xary -i corrupted_file.png\n "
83+ << " xary -e data.bin\n "
84+ << " xary -e data.bin -o encoded.xary\n "
85+ << " xary -d encoded.xary -o restored.bin\n " ;
7486}
7587
7688void ArgumentParser::printVersion () {
77- std::cout << " Xary Binary Engine v0.1.0 (C++20)\n " ;
89+ std::cout << " Xary Binary Engine v0.1.0 (C++20)\n " ;
7890}
7991
80- }
92+ } // namespace xary::cli
0 commit comments