From b326a301c3f48fb9b6d1f5a8c41bd8f5800f9d39 Mon Sep 17 00:00:00 2001 From: ronak69 Date: Tue, 8 Aug 2023 18:07:14 +0000 Subject: [PATCH] Userland: Pretty print the help text in BuggieBox Now, in the help text, the names of all the supported utilities and aliases are dynamically generated with the macro so that if new utilities are added in the future they will get included automatically. These utilities are printed in table-like format for some "aesthetics". --- Userland/BuggieBox/main.cpp | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/Userland/BuggieBox/main.cpp b/Userland/BuggieBox/main.cpp index 5621ae4cddb..52442c9210c 100644 --- a/Userland/BuggieBox/main.cpp +++ b/Userland/BuggieBox/main.cpp @@ -54,12 +54,30 @@ ENUMERATE_UTILITIES(DECLARE_ENTRYPOINT, SKIP) static void fail() { - out(stderr, "Direct running of BuggieBox was detected without finding a proper requested utility.\n"); - out(stderr, "The following programs are supported: uname, env, lsblk, file, df, mount, umount, mkdir, "); - out(stderr, "rmdir, rm, chown, chmod, cp, ln, ls, mv, cat, md5sum, sha1sum, sha256sum, sha512sum, sh, uniq, id, tail, "); - out(stderr, "find, less, mknod, ps\n"); - out(stderr, "To use one of these included utilities, create a symbolic link with the target being this binary, and ensure the basename"); - out(stderr, "is included within.\n"); +#define TOOL_NAME(name) #name##sv, +#define ALIAS_NAME(alias, name) #alias##sv, + auto const tool_names = { + ENUMERATE_UTILITIES(TOOL_NAME, ALIAS_NAME) + }; +#undef TOOL_NAME +#undef ALIAS_NAME + + outln(stderr); + outln(stderr, "Usage:"); + outln(stderr, "* Specify a utility as an argument:"); + outln(stderr, " $ BuggieBox UTILITY"); + outln(stderr, "* Create a symbolic link with the target being this binary,"); + outln(stderr, " and ensure the basename is one of the supported utilities' name."); + + outln(stderr); + outln(stderr, "The following utilities are supported:"); + int count = 0; + for (auto const& tool_name : tool_names) { + if (++count % 5 == 1) + out(stderr, "\n\t"); + out(stderr, "{:12}", tool_name); + } + outln(stderr); } struct Runner { @@ -89,14 +107,17 @@ static ErrorOr run_program(Main::Arguments arguments, LexicalPath const& ru static ErrorOr buggiebox_main(Main::Arguments arguments) { if (arguments.argc == 0) { + outln(stderr, "Detected directly running BuggieBox without specifying a utility."); fail(); return 1; } bool found_runner = false; LexicalPath runbase { arguments.strings[0] }; auto result = TRY(run_program(arguments, runbase, found_runner)); - if (!found_runner) + if (!found_runner) { + outln(stderr, "'{}' is not supported by BuggieBox.", runbase); fail(); + } return result; }