equal
deleted
inserted
replaced
|
1 #pragma once |
|
2 |
|
3 #include <locale.h> |
|
4 #include <string> |
|
5 #include <vector> |
|
6 #include <sstream> |
|
7 #include <locale> |
|
8 #include <codecvt> |
|
9 |
|
10 using namespace std; |
|
11 |
|
12 namespace relpipe { |
|
13 namespace cli { |
|
14 |
|
15 /** |
|
16 * TODO: move to relpipe-lib-cli (a common header-only library) |
|
17 */ |
|
18 class CLI { |
|
19 public: |
|
20 |
|
21 CLI(int argc, char* argv[]) { |
|
22 setlocale(LC_ALL, ""); |
|
23 |
|
24 this->argc = &argc; |
|
25 this->argv = &argv; |
|
26 |
|
27 program = convertor.from_bytes(argv[0]); |
|
28 |
|
29 for (int i = 1; i < argc; i++) { |
|
30 args.insert(args.end(), convertor.from_bytes(argv[i])); |
|
31 } |
|
32 |
|
33 } |
|
34 |
|
35 CLI(const CLI& orig) { |
|
36 } |
|
37 |
|
38 virtual ~CLI() { |
|
39 } |
|
40 |
|
41 const wstring programName() { |
|
42 return (const wstring) program; |
|
43 } |
|
44 |
|
45 const vector<wstring> arguments() { |
|
46 return (const vector<wstring>)args; |
|
47 } |
|
48 |
|
49 static const int EXIT_CODE_SUCCESS = 0; |
|
50 static const int EXIT_CODE_UNEXPECTED_ERROR = 1; |
|
51 static const int EXIT_CODE_BAD_SYNTAX = 3; |
|
52 static const int EXIT_CODE_UNKNOWN_COMMAND = 4; |
|
53 static const int EXIT_CODE_DATA_ERROR = 5; |
|
54 |
|
55 private: |
|
56 int* argc; |
|
57 char*** argv; |
|
58 wstring program; |
|
59 vector<wstring> args; |
|
60 wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings. |
|
61 }; |
|
62 |
|
63 } |
|
64 } |