55 bool parseBoolean(const relpipe::reader::string_t& value) { |
55 bool parseBoolean(const relpipe::reader::string_t& value) { |
56 if (value == L"true") return true; |
56 if (value == L"true") return true; |
57 else if (value == L"false") return false; |
57 else if (value == L"false") return false; |
58 else throw relpipe::cli::RelpipeCLIException(L"Unable to parse boolean value: " + value + L" (expecting true or false)", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
58 else throw relpipe::cli::RelpipeCLIException(L"Unable to parse boolean value: " + value + L" (expecting true or false)", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
59 } |
59 } |
|
60 |
|
61 Configuration::ColorScheme parseColorScheme(const relpipe::reader::string_t& value) { |
|
62 if (value == L"green-screen") return Configuration::ColorScheme::GreenScreen; |
|
63 else if (value == L"monochrome") return Configuration::ColorScheme::Monochrome; |
|
64 else if (value == L"midnight") return Configuration::ColorScheme::Midnight; |
|
65 else throw relpipe::cli::RelpipeCLIException(L"Unable to parse ColorScheme value: " + value + L" (expecting green-screen, monochrome or midnight)", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
|
66 } |
|
67 |
|
68 Configuration::TableStyle parseTableStyle(const relpipe::reader::string_t& value) { |
|
69 if (value == L"rounded") return Configuration::TableStyle::Rounded; |
|
70 else if (value == L"sharp") return Configuration::TableStyle::Sharp; |
|
71 else if (value == L"sharp-double") return Configuration::TableStyle::SharpDouble; |
|
72 else if (value == L"horizontal-only") return Configuration::TableStyle::HorizontalOnly; |
|
73 else if (value == L"ascii") return Configuration::TableStyle::Ascii; |
|
74 else throw relpipe::cli::RelpipeCLIException(L"Unable to parse TableStyle value: " + value + L" (expecting rounded, sharp, ascii)", relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
|
75 } |
60 |
76 |
61 public: |
77 public: |
62 |
78 |
63 static const relpipe::reader::string_t OPTION_RELATION; |
79 static const relpipe::reader::string_t OPTION_RELATION; |
64 static const relpipe::reader::string_t OPTION_WRITE_TYPES; |
80 static const relpipe::reader::string_t OPTION_WRITE_TYPES; |
65 static const relpipe::reader::string_t OPTION_WRITE_RELATION_NAME; |
81 static const relpipe::reader::string_t OPTION_WRITE_RELATION_NAME; |
66 static const relpipe::reader::string_t OPTION_WRITE_RECORD_COUNT; |
82 static const relpipe::reader::string_t OPTION_WRITE_RECORD_COUNT; |
|
83 static const relpipe::reader::string_t OPTION_COLOR_SCHEME; |
|
84 static const relpipe::reader::string_t OPTION_TABLE_STYLE; |
67 |
85 |
68 Configuration parse(const std::vector<relpipe::reader::string_t>& arguments) { |
86 Configuration parse(const std::vector<relpipe::reader::string_t>& arguments) { |
69 Configuration c; |
87 Configuration c; |
70 RelationConfiguration currentRelation; |
88 RelationConfiguration currentRelation; |
|
89 |
|
90 // TODO: global configuration of writeTypes, writeRelationName, writeRecordCount |
71 |
91 |
72 for (int i = 0; i < arguments.size();) { |
92 for (int i = 0; i < arguments.size();) { |
73 relpipe::reader::string_t option = readNext(arguments, i); |
93 relpipe::reader::string_t option = readNext(arguments, i); |
74 |
94 |
75 if (option == OPTION_RELATION) { |
95 if (option == OPTION_RELATION) { |
79 currentRelation.writeTypes = parseBoolean(readNext(arguments, i)); |
99 currentRelation.writeTypes = parseBoolean(readNext(arguments, i)); |
80 } else if (option == OPTION_WRITE_RELATION_NAME) { |
100 } else if (option == OPTION_WRITE_RELATION_NAME) { |
81 currentRelation.writeRelationName = parseBoolean(readNext(arguments, i)); |
101 currentRelation.writeRelationName = parseBoolean(readNext(arguments, i)); |
82 } else if (option == OPTION_WRITE_RECORD_COUNT) { |
102 } else if (option == OPTION_WRITE_RECORD_COUNT) { |
83 currentRelation.writeRecordCount = parseBoolean(readNext(arguments, i)); |
103 currentRelation.writeRecordCount = parseBoolean(readNext(arguments, i)); |
|
104 } else if (option == OPTION_COLOR_SCHEME) { |
|
105 c.colorScheme = parseColorScheme(readNext(arguments, i)); |
|
106 } else if (option == OPTION_TABLE_STYLE) { |
|
107 c.tableStyle = parseTableStyle(readNext(arguments, i)); |
84 } else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
108 } else throw relpipe::cli::RelpipeCLIException(L"Unsupported CLI option: " + option, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS); |
85 } |
109 } |
86 |
110 |
87 addRelation(c, currentRelation); // last relation |
111 addRelation(c, currentRelation); // last relation |
88 |
112 |
95 |
119 |
96 const relpipe::reader::string_t CLIParser::OPTION_RELATION = L"--relation"; |
120 const relpipe::reader::string_t CLIParser::OPTION_RELATION = L"--relation"; |
97 const relpipe::reader::string_t CLIParser::OPTION_WRITE_TYPES = L"--write-types"; |
121 const relpipe::reader::string_t CLIParser::OPTION_WRITE_TYPES = L"--write-types"; |
98 const relpipe::reader::string_t CLIParser::OPTION_WRITE_RELATION_NAME = L"--write-relation-name"; |
122 const relpipe::reader::string_t CLIParser::OPTION_WRITE_RELATION_NAME = L"--write-relation-name"; |
99 const relpipe::reader::string_t CLIParser::OPTION_WRITE_RECORD_COUNT = L"--write-record-count"; |
123 const relpipe::reader::string_t CLIParser::OPTION_WRITE_RECORD_COUNT = L"--write-record-count"; |
|
124 const relpipe::reader::string_t CLIParser::OPTION_COLOR_SCHEME = L"--color-scheme"; |
|
125 const relpipe::reader::string_t CLIParser::OPTION_TABLE_STYLE = L"--table-style"; |
100 |
126 |
101 } |
127 } |
102 } |
128 } |
103 } |
129 } |