| 249 | }; |
| 250 | |
| 251 | void ShellState::PrintUsage() { |
| 252 | ShellHighlight highlighter(*this); |
| 253 | highlighter.PrintText("Usage: ", PrintOutput::STDOUT, PrintColor::STANDARD, PrintIntensity::BOLD); |
| 254 | highlighter.PrintText(program_name, PrintOutput::STDOUT, HighlightElementType::KEYWORD); |
| 255 | highlighter.PrintText(" [OPTIONS] FILENAME [SQL]\n\n", PrintOutput::STDOUT, HighlightElementType::STRING_CONSTANT); |
| 256 | highlighter.PrintText("FILENAME", PrintOutput::STDOUT, PrintColor::STANDARD, PrintIntensity::BOLD); |
| 257 | PrintF(" is the name of a DuckDB database. A new database is created\n" |
| 258 | "if the file does not previously exist.\n\n"); |
| 259 | highlighter.PrintText("OPTIONS:\n", PrintOutput::STDOUT, PrintColor::STANDARD, PrintIntensity::BOLD); |
| 260 | constexpr idx_t INITIAL_SPACING = 2; |
| 261 | constexpr idx_t MIN_SPACING = 4; |
| 262 | vector<PrintOptionInfo> print_options; |
| 263 | for (idx_t c = 0; command_line_options[c].option; c++) { |
| 264 | auto &option = command_line_options[c]; |
| 265 | PrintOptionInfo print_option; |
| 266 | print_option.command_name = string(INITIAL_SPACING, ' ') + "-" + option.option; |
| 267 | print_option.arguments = option.arguments; |
| 268 | print_option.description = option.description; |
| 269 | print_options.push_back(std::move(print_option)); |
| 270 | } |
| 271 | idx_t max_lhs_length = 0; |
| 272 | for (auto &option : print_options) { |
| 273 | auto lhs_length = option.command_name.size() + option.arguments.size(); |
| 274 | if (!option.arguments.empty()) { |
| 275 | lhs_length++; |
| 276 | } |
| 277 | if (lhs_length > max_lhs_length) { |
| 278 | max_lhs_length = lhs_length; |
| 279 | } |
| 280 | } |
| 281 | // print the options |
| 282 | for (auto &option : print_options) { |
| 283 | auto lhs_length = option.command_name.size() + option.arguments.size(); |
| 284 | if (!option.arguments.empty()) { |
| 285 | lhs_length++; |
| 286 | } |
| 287 | idx_t padding = max_lhs_length - lhs_length + MIN_SPACING; |
| 288 | string spaces(padding, ' '); |
| 289 | highlighter.PrintText(option.command_name, PrintOutput::STDOUT, HighlightElementType::KEYWORD); |
| 290 | if (!option.arguments.empty()) { |
| 291 | highlighter.PrintText(" " + option.arguments, PrintOutput::STDOUT, HighlightElementType::STRING_CONSTANT); |
| 292 | } |
| 293 | PrintF("%s%s\n", spaces.c_str(), option.description.c_str()); |
| 294 | } |
| 295 | ShellState::Exit(0); |
| 296 | } |
| 297 | |
| 298 | } // namespace duckdb_shell |