Skip to content

Commit 7f7c254

Browse files
[dbtool] Move examples behind --show-examples
The Examples block bloated the bottom of `dbtool --help`, pushing the options listing off the screen. Hoist it behind a dedicated `--show-examples` flag and leave a one-line pointer at the end of help output so discoverability is preserved without forcing the whole example wall on every `--help` reader. Signed-off-by: Christian Parpart <christian@parpart.family>
1 parent 4fe38f4 commit 7f7c254

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/tools/dbtool/main.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,20 @@ void PrintUsage()
197197
std::println(" {}--schema-only{} Backup/restore schema only, skip data",
198198
c.option, c.reset);
199199
std::println(" {}--quiet{} Suppress progress output", c.option, c.reset);
200+
std::println(" {}--show-examples{} Show usage examples and exit", c.option, c.reset);
200201
std::println(" {}--help{} Show this help message", c.option, c.reset);
201202
std::println("");
203+
std::println("Run {}dbtool --show-examples{} to see usage examples.", c.option, c.reset);
204+
// clang-format on
205+
}
206+
207+
void PrintExamples()
208+
{
209+
// clang-format off
210+
auto const c = IsStdoutTerminal() ? HelpColors::Colored() : HelpColors::Plain();
202211

203212
std::println("{}Examples:{}", c.heading, c.reset);
213+
std::println("");
204214

205215
std::println(" {}# Apply pending migrations using an SQLite database file via ODBC:{}", c.example, c.reset);
206216
std::println(" {}dbtool migrate --connection-string \"DRIVER=SQLite3;Database=test.db\"{}", c.code, c.reset);
@@ -409,6 +419,11 @@ std::expected<Options, std::string> ParseArguments(int argc, char** argv)
409419
options.command = "help";
410420
break;
411421
}
422+
else if (arg == "--show-examples")
423+
{
424+
options.command = "show-examples";
425+
break;
426+
}
412427
else if (arg == "--plugins-dir")
413428
{
414429
if (i + 1 >= argc)
@@ -2239,6 +2254,12 @@ int main(int argc, char** argv)
22392254
return EXIT_SUCCESS;
22402255
}
22412256

2257+
if (options.command == "show-examples")
2258+
{
2259+
PrintExamples();
2260+
return EXIT_SUCCESS;
2261+
}
2262+
22422263
if (options.command == "resolve-secret")
22432264
return ResolveSecretCommand(options);
22442265

0 commit comments

Comments
 (0)