mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:27:45 +00:00
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".
This commit is contained in:
parent
06ee4b66d0
commit
b326a301c3
1 changed files with 28 additions and 7 deletions
|
@ -54,12 +54,30 @@ ENUMERATE_UTILITIES(DECLARE_ENTRYPOINT, SKIP)
|
||||||
|
|
||||||
static void fail()
|
static void fail()
|
||||||
{
|
{
|
||||||
out(stderr, "Direct running of BuggieBox was detected without finding a proper requested utility.\n");
|
#define TOOL_NAME(name) #name##sv,
|
||||||
out(stderr, "The following programs are supported: uname, env, lsblk, file, df, mount, umount, mkdir, ");
|
#define ALIAS_NAME(alias, name) #alias##sv,
|
||||||
out(stderr, "rmdir, rm, chown, chmod, cp, ln, ls, mv, cat, md5sum, sha1sum, sha256sum, sha512sum, sh, uniq, id, tail, ");
|
auto const tool_names = {
|
||||||
out(stderr, "find, less, mknod, ps\n");
|
ENUMERATE_UTILITIES(TOOL_NAME, ALIAS_NAME)
|
||||||
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");
|
#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 {
|
struct Runner {
|
||||||
|
@ -89,14 +107,17 @@ static ErrorOr<int> run_program(Main::Arguments arguments, LexicalPath const& ru
|
||||||
static ErrorOr<int> buggiebox_main(Main::Arguments arguments)
|
static ErrorOr<int> buggiebox_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
if (arguments.argc == 0) {
|
if (arguments.argc == 0) {
|
||||||
|
outln(stderr, "Detected directly running BuggieBox without specifying a utility.");
|
||||||
fail();
|
fail();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
bool found_runner = false;
|
bool found_runner = false;
|
||||||
LexicalPath runbase { arguments.strings[0] };
|
LexicalPath runbase { arguments.strings[0] };
|
||||||
auto result = TRY(run_program(arguments, runbase, found_runner));
|
auto result = TRY(run_program(arguments, runbase, found_runner));
|
||||||
if (!found_runner)
|
if (!found_runner) {
|
||||||
|
outln(stderr, "'{}' is not supported by BuggieBox.", runbase);
|
||||||
fail();
|
fail();
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue