mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:27:45 +00:00
LibCore+Base: Add way to hide ArgsParser opt.s from specific usage texts
This adds the ability to hide certain options from certain help texts. `--complete` is always hidden, whereas `--help` and `--version` are hidden from Markdown help text only. Note that in all cases these three options are hidden from the short usage line.
This commit is contained in:
parent
a387b822a0
commit
cbc89632b9
26 changed files with 57 additions and 115 deletions
|
@ -10,9 +10,6 @@ $ UserspaceEmulator [--report-to-debug] [--pause] [--profile] [--profile-interva
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `--report-to-debug`: Write reports to the debug log
|
* `--report-to-debug`: Write reports to the debug log
|
||||||
* `-p`, `--pause`: Pause on startup
|
* `-p`, `--pause`: Pause on startup
|
||||||
* `--profile`: Generate a ProfileViewer-compatible profile
|
* `--profile`: Generate a ProfileViewer-compatible profile
|
||||||
|
|
|
@ -14,9 +14,6 @@ Show or modify values in the configuration files through ConfigServer.
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `-r`, `--remove`: Remove key
|
* `-r`, `--remove`: Remove key
|
||||||
|
|
||||||
## Arguments:
|
## Arguments:
|
||||||
|
|
|
@ -14,9 +14,6 @@ Open a fortune cookie, receive a free quote for the day!
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
|
|
||||||
## Arguments:
|
## Arguments:
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,6 @@ $ grep [--recursive] [--extended-regexp] [--regexp Pattern] [-i] [--line-numbers
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `-r`, `--recursive`: Recursively scan files
|
* `-r`, `--recursive`: Recursively scan files
|
||||||
* `-E`, `--extended-regexp`: Extended regular expressions
|
* `-E`, `--extended-regexp`: Extended regular expressions
|
||||||
* `-e Pattern`, `--regexp Pattern`: Pattern
|
* `-e Pattern`, `--regexp Pattern`: Pattern
|
||||||
|
|
|
@ -10,9 +10,6 @@ $ gunzip [--keep] [--stdout] <FILE...>
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `-k`, `--keep`: Keep (don't delete) input files
|
* `-k`, `--keep`: Keep (don't delete) input files
|
||||||
* `-c`, `--stdout`: Write to stdout, keep original files unchanged
|
* `-c`, `--stdout`: Write to stdout, keep original files unchanged
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,6 @@ $ gzip [--keep] [--stdout] [--decompress] <FILES...>
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `-k`, `--keep`: Keep (don't delete) input files
|
* `-k`, `--keep`: Keep (don't delete) input files
|
||||||
* `-c`, `--stdout`: Write to stdout, keep original files unchanged
|
* `-c`, `--stdout`: Write to stdout, keep original files unchanged
|
||||||
* `-d`, `--decompress`: Decompress
|
* `-d`, `--decompress`: Decompress
|
||||||
|
|
|
@ -14,9 +14,6 @@ Display or modify the configuration of each network interface.
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `-i ip`, `--ipv4 ip`: Set the IP address of the selected network
|
* `-i ip`, `--ipv4 ip`: Set the IP address of the selected network
|
||||||
* `-a adapter`, `--adapter adapter`: Select a specific network adapter to configure
|
* `-a adapter`, `--adapter adapter`: Select a specific network adapter to configure
|
||||||
* `-g gateway`, `--gateway gateway`: Set the default gateway of the selected network
|
* `-g gateway`, `--gateway gateway`: Set the default gateway of the selected network
|
||||||
|
|
|
@ -14,9 +14,6 @@ List open files of a processes. This can mean actual files in the file system, s
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `-p pid`: Select by PID
|
* `-p pid`: Select by PID
|
||||||
* `-d fd`: Select by file descriptor
|
* `-d fd`: Select by file descriptor
|
||||||
* `-u login/UID`: Select by login/UID
|
* `-u login/UID`: Select by login/UID
|
||||||
|
|
|
@ -14,9 +14,6 @@ Network cat: Connect to network sockets as if it were a file.
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `-l`, `--listen`: Listen instead of connecting
|
* `-l`, `--listen`: Listen instead of connecting
|
||||||
* `-v`, `--verbose`: Log everything that's happening
|
* `-v`, `--verbose`: Log everything that's happening
|
||||||
* `-u`, `--udp`: UDP mode
|
* `-u`, `--udp`: UDP mode
|
||||||
|
|
|
@ -14,9 +14,6 @@ Display network connections
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `-a`, `--all`: Display both listening and non-listening sockets
|
* `-a`, `--all`: Display both listening and non-listening sockets
|
||||||
* `-l`, `--list`: Display only listening sockets
|
* `-l`, `--list`: Display only listening sockets
|
||||||
* `-t`, `--tcp`: Display only TCP network connections
|
* `-t`, `--tcp`: Display only TCP network connections
|
||||||
|
|
|
@ -10,9 +10,6 @@ $ nl [--body-numbering style] [--increment number] [--separator string] [--start
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `-b style`, `--body-numbering style`: Line numbering style: 't' for non-empty lines, 'a' for all lines, 'n' for no lines
|
* `-b style`, `--body-numbering style`: Line numbering style: 't' for non-empty lines, 'a' for all lines, 'n' for no lines
|
||||||
* `-i number`, `--increment number`: Line count increment
|
* `-i number`, `--increment number`: Line count increment
|
||||||
* `-s string`, `--separator string`: Separator between line numbers and lines
|
* `-s string`, `--separator string`: Separator between line numbers and lines
|
||||||
|
|
|
@ -10,9 +10,6 @@ $ ntpquery [--adjust] [--set] [--verbose] [host]
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `-a`, `--adjust`: Gradually adjust system time (requires root)
|
* `-a`, `--adjust`: Gradually adjust system time (requires root)
|
||||||
* `-s`, `--set`: Immediately set system time (requires root)
|
* `-s`, `--set`: Immediately set system time (requires root)
|
||||||
* `-v`, `--verbose`: Verbose output
|
* `-v`, `--verbose`: Verbose output
|
||||||
|
|
|
@ -14,9 +14,6 @@ Modify an account password.
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `-d`, `--delete`: Delete password
|
* `-d`, `--delete`: Delete password
|
||||||
* `-l`, `--lock`: Lock password
|
* `-l`, `--lock`: Lock password
|
||||||
* `-u`, `--unlock`: Unlock password
|
* `-u`, `--unlock`: Unlock password
|
||||||
|
|
|
@ -10,9 +10,6 @@ $ profile [-p PID] [-a] [-e] [-d] [-f] [-w] [-c command] [-t event_type]
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `-p PID`: Target PID
|
* `-p PID`: Target PID
|
||||||
* `-a`: Profile all processes (super-user only), result at /proc/profile
|
* `-a`: Profile all processes (super-user only), result at /proc/profile
|
||||||
* `-e`: Enable
|
* `-e`: Enable
|
||||||
|
|
|
@ -10,9 +10,6 @@ $ readelf [--all] [--file-header] [--program-headers] [--section-headers] [--hea
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `-a`, `--all`: Display all
|
* `-a`, `--all`: Display all
|
||||||
* `-h`, `--file-header`: Display ELF header
|
* `-h`, `--file-header`: Display ELF header
|
||||||
* `-l`, `--program-headers`: Display program headers
|
* `-l`, `--program-headers`: Display program headers
|
||||||
|
|
|
@ -10,9 +10,6 @@ $ shot [--clipboard] [--delay seconds] [--screen index] [--region] [output]
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `-c`, `--clipboard`: Output to clipboard
|
* `-c`, `--clipboard`: Output to clipboard
|
||||||
* `-d seconds`, `--delay seconds`: Seconds to wait before taking a screenshot
|
* `-d seconds`, `--delay seconds`: Seconds to wait before taking a screenshot
|
||||||
* `-s index`, `--screen index`: The index of the screen (default: -1 for all screens)
|
* `-s index`, `--screen index`: The index of the screen (default: -1 for all screens)
|
||||||
|
|
|
@ -14,9 +14,6 @@ This is a client for the SerenitySQL database server.
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `-d database`, `--database database`: Database to connect to
|
* `-d database`, `--database database`: Database to connect to
|
||||||
* `-r file`, `--read file`: File to read
|
* `-r file`, `--read file`: File to read
|
||||||
* `-s file`, `--source file`: File to source
|
* `-s file`, `--source file`: File to source
|
||||||
|
|
|
@ -14,9 +14,6 @@ Trace all syscalls and their result.
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `-p pid`, `--pid pid`: Trace the given PID
|
* `-p pid`, `--pid pid`: Trace the given PID
|
||||||
* `-o output`, `--output output`: Filename to write output to
|
* `-o output`, `--output output`: Filename to write output to
|
||||||
* `-e exclude`, `--exclude exclude`: Comma-delimited syscalls to exclude
|
* `-e exclude`, `--exclude exclude`: Comma-delimited syscalls to exclude
|
||||||
|
|
|
@ -14,9 +14,6 @@ Print the end ('tail') of a file.
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `-f`, `--follow`: Output data as it is written to the file
|
* `-f`, `--follow`: Output data as it is written to the file
|
||||||
* `-n number`, `--lines number`: Fetch the specified number of lines
|
* `-n number`, `--lines number`: Fetch the specified number of lines
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,6 @@ $ tr [--complement] [--delete] [--squeeze-repeats] <from> [to]
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `-c`, `--complement`: Take the complement of the first set
|
* `-c`, `--complement`: Take the complement of the first set
|
||||||
* `-d`, `--delete`: Delete characters instead of replacing
|
* `-d`, `--delete`: Delete characters instead of replacing
|
||||||
* `-s`, `--squeeze-repeats`: Omit repeated characters listed in the last given set from the output
|
* `-s`, `--squeeze-repeats`: Omit repeated characters listed in the last given set from the output
|
||||||
|
|
|
@ -10,9 +10,6 @@ $ traceroute [--max-hops hops] [--max-retries tries] [--timeout seconds] <destin
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `-h hops`, `--max-hops hops`: use at most <hops> to the destination
|
* `-h hops`, `--max-hops hops`: use at most <hops> to the destination
|
||||||
* `-r tries`, `--max-retries tries`: retry TTL at most <tries> times
|
* `-r tries`, `--max-retries tries`: retry TTL at most <tries> times
|
||||||
* `-t seconds`, `--timeout seconds`: wait at most <seconds> for a response
|
* `-t seconds`, `--timeout seconds`: wait at most <seconds> for a response
|
||||||
|
|
|
@ -10,9 +10,6 @@ $ tree [--all] [--only-directories] [--maximum-depth level] [directories...]
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `-a`, `--all`: Show hidden files
|
* `-a`, `--all`: Show hidden files
|
||||||
* `-d`, `--only-directories`: Show only directories
|
* `-d`, `--only-directories`: Show only directories
|
||||||
* `-L level`, `--maximum-depth level`: Maximum depth of the tree
|
* `-L level`, `--maximum-depth level`: Maximum depth of the tree
|
||||||
|
|
|
@ -10,9 +10,6 @@ $ truncate [--size size] [--reference file] <file>
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `-s size`, `--size size`: Resize the target file to (or by) this size. Prefix with + or - to expand or shrink the file, or a bare number to set the size exactly
|
* `-s size`, `--size size`: Resize the target file to (or by) this size. Prefix with + or - to expand or shrink the file, or a bare number to set the size exactly
|
||||||
* `-r file`, `--reference file`: Resize the target file to match the size of this one
|
* `-r file`, `--reference file`: Resize the target file to match the size of this one
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,6 @@ $ utmpupdate [--create] [--delete] [--PID PID] [--from From] <tty>
|
||||||
|
|
||||||
## Options:
|
## Options:
|
||||||
|
|
||||||
* `--help`: Display help message and exit
|
|
||||||
* `--version`: Print version
|
|
||||||
* `--complete`: Perform autocompletion
|
|
||||||
* `-c`, `--create`: Create entry
|
* `-c`, `--create`: Create entry
|
||||||
* `-d`, `--delete`: Delete entry
|
* `-d`, `--delete`: Delete entry
|
||||||
* `-p PID`, `--PID PID`: PID
|
* `-p PID`, `--PID PID`: PID
|
||||||
|
|
|
@ -29,9 +29,9 @@ namespace Core {
|
||||||
|
|
||||||
ArgsParser::ArgsParser()
|
ArgsParser::ArgsParser()
|
||||||
{
|
{
|
||||||
add_option(m_show_help, "Display help message and exit", "help", 0, true);
|
add_option(m_show_help, "Display help message and exit", "help", 0, OptionHideMode::Markdown);
|
||||||
add_option(m_show_version, "Print version", "version", 0, true);
|
add_option(m_show_version, "Print version", "version", 0, OptionHideMode::Markdown);
|
||||||
add_option(m_perform_autocomplete, "Perform autocompletion", "complete", 0, true);
|
add_option(m_perform_autocomplete, "Perform autocompletion", "complete", 0, OptionHideMode::CommandLineAndMarkdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ArgsParser::parse(int argc, char* const* argv, FailureBehavior failure_behavior)
|
bool ArgsParser::parse(int argc, char* const* argv, FailureBehavior failure_behavior)
|
||||||
|
@ -198,7 +198,7 @@ void ArgsParser::print_usage_terminal(FILE* file, char const* argv0)
|
||||||
out(file, "Usage:\n\t\033[1m{}\033[0m", argv0);
|
out(file, "Usage:\n\t\033[1m{}\033[0m", argv0);
|
||||||
|
|
||||||
for (auto& opt : m_options) {
|
for (auto& opt : m_options) {
|
||||||
if (opt.hide_from_help_and_autocomplete)
|
if (opt.hide_mode != OptionHideMode::None)
|
||||||
continue;
|
continue;
|
||||||
if (opt.requires_argument)
|
if (opt.requires_argument)
|
||||||
out(file, " [{} {}]", opt.name_for_display(), opt.value_name);
|
out(file, " [{} {}]", opt.name_for_display(), opt.value_name);
|
||||||
|
@ -228,6 +228,9 @@ void ArgsParser::print_usage_terminal(FILE* file, char const* argv0)
|
||||||
if (!m_options.is_empty())
|
if (!m_options.is_empty())
|
||||||
outln(file, "\nOptions:");
|
outln(file, "\nOptions:");
|
||||||
for (auto& opt : m_options) {
|
for (auto& opt : m_options) {
|
||||||
|
if (opt.hide_mode == OptionHideMode::CommandLineAndMarkdown)
|
||||||
|
continue;
|
||||||
|
|
||||||
auto print_argument = [&]() {
|
auto print_argument = [&]() {
|
||||||
if (opt.value_name) {
|
if (opt.value_name) {
|
||||||
if (opt.requires_argument)
|
if (opt.requires_argument)
|
||||||
|
@ -270,7 +273,7 @@ void ArgsParser::print_usage_markdown(FILE* file, char const* argv0)
|
||||||
|
|
||||||
out(file, "\n## Synopsis\n\n```sh\n$ {}", argv0);
|
out(file, "\n## Synopsis\n\n```sh\n$ {}", argv0);
|
||||||
for (auto& opt : m_options) {
|
for (auto& opt : m_options) {
|
||||||
if (opt.hide_from_help_and_autocomplete)
|
if (opt.hide_mode != OptionHideMode::None)
|
||||||
continue;
|
continue;
|
||||||
if (opt.requires_argument)
|
if (opt.requires_argument)
|
||||||
out(file, " [{} {}]", opt.name_for_display(), opt.value_name);
|
out(file, " [{} {}]", opt.name_for_display(), opt.value_name);
|
||||||
|
@ -299,6 +302,9 @@ void ArgsParser::print_usage_markdown(FILE* file, char const* argv0)
|
||||||
if (!m_options.is_empty())
|
if (!m_options.is_empty())
|
||||||
outln(file, "\n## Options:\n");
|
outln(file, "\n## Options:\n");
|
||||||
for (auto& opt : m_options) {
|
for (auto& opt : m_options) {
|
||||||
|
if (opt.hide_mode == OptionHideMode::Markdown || opt.hide_mode == OptionHideMode::CommandLineAndMarkdown)
|
||||||
|
continue;
|
||||||
|
|
||||||
auto print_argument = [&]() {
|
auto print_argument = [&]() {
|
||||||
if (opt.value_name != nullptr) {
|
if (opt.value_name != nullptr) {
|
||||||
if (opt.requires_argument)
|
if (opt.requires_argument)
|
||||||
|
@ -347,7 +353,7 @@ void ArgsParser::add_option(Option&& option)
|
||||||
m_options.append(move(option));
|
m_options.append(move(option));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArgsParser::add_ignored(char const* long_name, char short_name, bool hidden)
|
void ArgsParser::add_ignored(char const* long_name, char short_name, OptionHideMode hide_mode)
|
||||||
{
|
{
|
||||||
Option option {
|
Option option {
|
||||||
false,
|
false,
|
||||||
|
@ -358,12 +364,12 @@ void ArgsParser::add_ignored(char const* long_name, char short_name, bool hidden
|
||||||
[](char const*) {
|
[](char const*) {
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
hidden,
|
hide_mode,
|
||||||
};
|
};
|
||||||
add_option(move(option));
|
add_option(move(option));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArgsParser::add_option(bool& value, char const* help_string, char const* long_name, char short_name, bool hidden)
|
void ArgsParser::add_option(bool& value, char const* help_string, char const* long_name, char short_name, OptionHideMode hide_mode)
|
||||||
{
|
{
|
||||||
Option option {
|
Option option {
|
||||||
false,
|
false,
|
||||||
|
@ -376,12 +382,12 @@ void ArgsParser::add_option(bool& value, char const* help_string, char const* lo
|
||||||
value = true;
|
value = true;
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
hidden,
|
hide_mode,
|
||||||
};
|
};
|
||||||
add_option(move(option));
|
add_option(move(option));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArgsParser::add_option(char const*& value, char const* help_string, char const* long_name, char short_name, char const* value_name, bool hidden)
|
void ArgsParser::add_option(char const*& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode)
|
||||||
{
|
{
|
||||||
Option option {
|
Option option {
|
||||||
true,
|
true,
|
||||||
|
@ -393,12 +399,12 @@ void ArgsParser::add_option(char const*& value, char const* help_string, char co
|
||||||
value = s;
|
value = s;
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
hidden,
|
hide_mode,
|
||||||
};
|
};
|
||||||
add_option(move(option));
|
add_option(move(option));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArgsParser::add_option(String& value, char const* help_string, char const* long_name, char short_name, char const* value_name, bool hidden)
|
void ArgsParser::add_option(String& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode)
|
||||||
{
|
{
|
||||||
Option option {
|
Option option {
|
||||||
true,
|
true,
|
||||||
|
@ -410,12 +416,12 @@ void ArgsParser::add_option(String& value, char const* help_string, char const*
|
||||||
value = s;
|
value = s;
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
hidden,
|
hide_mode,
|
||||||
};
|
};
|
||||||
add_option(move(option));
|
add_option(move(option));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArgsParser::add_option(StringView& value, char const* help_string, char const* long_name, char short_name, char const* value_name, bool hidden)
|
void ArgsParser::add_option(StringView& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode)
|
||||||
{
|
{
|
||||||
Option option {
|
Option option {
|
||||||
true,
|
true,
|
||||||
|
@ -427,12 +433,12 @@ void ArgsParser::add_option(StringView& value, char const* help_string, char con
|
||||||
value = s;
|
value = s;
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
hidden,
|
hide_mode,
|
||||||
};
|
};
|
||||||
add_option(move(option));
|
add_option(move(option));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArgsParser::add_option(int& value, char const* help_string, char const* long_name, char short_name, char const* value_name, bool hidden)
|
void ArgsParser::add_option(int& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode)
|
||||||
{
|
{
|
||||||
Option option {
|
Option option {
|
||||||
true,
|
true,
|
||||||
|
@ -445,12 +451,12 @@ void ArgsParser::add_option(int& value, char const* help_string, char const* lon
|
||||||
value = opt.value_or(0);
|
value = opt.value_or(0);
|
||||||
return opt.has_value();
|
return opt.has_value();
|
||||||
},
|
},
|
||||||
hidden,
|
hide_mode,
|
||||||
};
|
};
|
||||||
add_option(move(option));
|
add_option(move(option));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArgsParser::add_option(unsigned& value, char const* help_string, char const* long_name, char short_name, char const* value_name, bool hidden)
|
void ArgsParser::add_option(unsigned& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode)
|
||||||
{
|
{
|
||||||
Option option {
|
Option option {
|
||||||
true,
|
true,
|
||||||
|
@ -463,12 +469,12 @@ void ArgsParser::add_option(unsigned& value, char const* help_string, char const
|
||||||
value = opt.value_or(0);
|
value = opt.value_or(0);
|
||||||
return opt.has_value();
|
return opt.has_value();
|
||||||
},
|
},
|
||||||
hidden,
|
hide_mode,
|
||||||
};
|
};
|
||||||
add_option(move(option));
|
add_option(move(option));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArgsParser::add_option(double& value, char const* help_string, char const* long_name, char short_name, char const* value_name, bool hidden)
|
void ArgsParser::add_option(double& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode)
|
||||||
{
|
{
|
||||||
Option option {
|
Option option {
|
||||||
true,
|
true,
|
||||||
|
@ -481,12 +487,12 @@ void ArgsParser::add_option(double& value, char const* help_string, char const*
|
||||||
value = opt.value_or(0.0);
|
value = opt.value_or(0.0);
|
||||||
return opt.has_value();
|
return opt.has_value();
|
||||||
},
|
},
|
||||||
hidden,
|
hide_mode,
|
||||||
};
|
};
|
||||||
add_option(move(option));
|
add_option(move(option));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArgsParser::add_option(Optional<double>& value, char const* help_string, char const* long_name, char short_name, char const* value_name, bool hidden)
|
void ArgsParser::add_option(Optional<double>& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode)
|
||||||
{
|
{
|
||||||
Option option {
|
Option option {
|
||||||
true,
|
true,
|
||||||
|
@ -498,12 +504,12 @@ void ArgsParser::add_option(Optional<double>& value, char const* help_string, ch
|
||||||
value = convert_to_double(s);
|
value = convert_to_double(s);
|
||||||
return value.has_value();
|
return value.has_value();
|
||||||
},
|
},
|
||||||
hidden,
|
hide_mode,
|
||||||
};
|
};
|
||||||
add_option(move(option));
|
add_option(move(option));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArgsParser::add_option(Optional<size_t>& value, char const* help_string, char const* long_name, char short_name, char const* value_name, bool hidden)
|
void ArgsParser::add_option(Optional<size_t>& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode)
|
||||||
{
|
{
|
||||||
Option option {
|
Option option {
|
||||||
true,
|
true,
|
||||||
|
@ -515,12 +521,12 @@ void ArgsParser::add_option(Optional<size_t>& value, char const* help_string, ch
|
||||||
value = AK::StringUtils::convert_to_uint<size_t>(s);
|
value = AK::StringUtils::convert_to_uint<size_t>(s);
|
||||||
return value.has_value();
|
return value.has_value();
|
||||||
},
|
},
|
||||||
hidden,
|
hide_mode,
|
||||||
};
|
};
|
||||||
add_option(move(option));
|
add_option(move(option));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArgsParser::add_option(Vector<size_t>& values, char const* help_string, char const* long_name, char short_name, char const* value_name, char separator, bool hidden)
|
void ArgsParser::add_option(Vector<size_t>& values, char const* help_string, char const* long_name, char short_name, char const* value_name, char separator, OptionHideMode hide_mode)
|
||||||
{
|
{
|
||||||
Option option {
|
Option option {
|
||||||
true,
|
true,
|
||||||
|
@ -540,7 +546,7 @@ void ArgsParser::add_option(Vector<size_t>& values, char const* help_string, cha
|
||||||
|
|
||||||
return parsed_all_values;
|
return parsed_all_values;
|
||||||
},
|
},
|
||||||
hidden
|
hide_mode
|
||||||
};
|
};
|
||||||
|
|
||||||
add_option(move(option));
|
add_option(move(option));
|
||||||
|
@ -718,7 +724,7 @@ void ArgsParser::autocomplete(FILE* file, StringView program_name, Span<char con
|
||||||
|
|
||||||
// Look for a long option
|
// Look for a long option
|
||||||
auto option_pattern = argument.substring_view(2);
|
auto option_pattern = argument.substring_view(2);
|
||||||
auto it = m_options.find_if([&](auto& option) { return !option.hide_from_help_and_autocomplete && StringView(option.long_name) == option_pattern; });
|
auto it = m_options.find_if([&](auto& option) { return option.hide_mode != OptionHideMode::None && StringView(option.long_name) == option_pattern; });
|
||||||
if (it.is_end())
|
if (it.is_end())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -738,7 +744,7 @@ void ArgsParser::autocomplete(FILE* file, StringView program_name, Span<char con
|
||||||
|
|
||||||
// Look for a short option
|
// Look for a short option
|
||||||
auto option_pattern = argument[argument.length() - 1];
|
auto option_pattern = argument[argument.length() - 1];
|
||||||
auto it = m_options.find_if([&](auto& option) { return !option.hide_from_help_and_autocomplete && option.short_name == option_pattern; });
|
auto it = m_options.find_if([&](auto& option) { return option.hide_mode != OptionHideMode::None && option.short_name == option_pattern; });
|
||||||
|
|
||||||
if (it.is_end())
|
if (it.is_end())
|
||||||
continue;
|
continue;
|
||||||
|
@ -767,7 +773,7 @@ void ArgsParser::autocomplete(FILE* file, StringView program_name, Span<char con
|
||||||
// Complete a long option.
|
// Complete a long option.
|
||||||
auto option_pattern = option_to_complete.substring_view(2);
|
auto option_pattern = option_to_complete.substring_view(2);
|
||||||
for (auto& option : m_options) {
|
for (auto& option : m_options) {
|
||||||
if (option.hide_from_help_and_autocomplete)
|
if (option.hide_mode != OptionHideMode::None)
|
||||||
continue;
|
continue;
|
||||||
StringView option_string = option.long_name;
|
StringView option_string = option.long_name;
|
||||||
if (option_string.starts_with(option_pattern)) {
|
if (option_string.starts_with(option_pattern)) {
|
||||||
|
@ -777,7 +783,7 @@ void ArgsParser::autocomplete(FILE* file, StringView program_name, Span<char con
|
||||||
} else {
|
} else {
|
||||||
// Complete a short option, note that we're not going to attempt to 'match' anything here.
|
// Complete a short option, note that we're not going to attempt to 'match' anything here.
|
||||||
for (auto& option : m_options) {
|
for (auto& option : m_options) {
|
||||||
if (option.hide_from_help_and_autocomplete)
|
if (option.hide_mode != OptionHideMode::None)
|
||||||
continue;
|
continue;
|
||||||
if (option.short_name == 0)
|
if (option.short_name == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -30,6 +30,14 @@ public:
|
||||||
Ignore,
|
Ignore,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// When an option is hidden.
|
||||||
|
/// If the hide mode is not None, then it's always hidden from the usage/synopsis.
|
||||||
|
enum class OptionHideMode {
|
||||||
|
None,
|
||||||
|
Markdown,
|
||||||
|
CommandLineAndMarkdown,
|
||||||
|
};
|
||||||
|
|
||||||
struct Option {
|
struct Option {
|
||||||
bool requires_argument { true };
|
bool requires_argument { true };
|
||||||
char const* help_string { nullptr };
|
char const* help_string { nullptr };
|
||||||
|
@ -37,7 +45,7 @@ public:
|
||||||
char short_name { 0 };
|
char short_name { 0 };
|
||||||
char const* value_name { nullptr };
|
char const* value_name { nullptr };
|
||||||
Function<bool(char const*)> accept_value;
|
Function<bool(char const*)> accept_value;
|
||||||
bool hide_from_help_and_autocomplete { false };
|
OptionHideMode hide_mode { OptionHideMode::None };
|
||||||
|
|
||||||
String name_for_display() const
|
String name_for_display() const
|
||||||
{
|
{
|
||||||
|
@ -70,17 +78,17 @@ public:
|
||||||
void print_version(FILE*);
|
void print_version(FILE*);
|
||||||
|
|
||||||
void add_option(Option&&);
|
void add_option(Option&&);
|
||||||
void add_ignored(char const* long_name, char short_name, bool hidden = false);
|
void add_ignored(char const* long_name, char short_name, OptionHideMode hide_mode = OptionHideMode::None);
|
||||||
void add_option(bool& value, char const* help_string, char const* long_name, char short_name, bool hidden = false);
|
void add_option(bool& value, char const* help_string, char const* long_name, char short_name, OptionHideMode hide_mode = OptionHideMode::None);
|
||||||
void add_option(char const*& value, char const* help_string, char const* long_name, char short_name, char const* value_name, bool hidden = false);
|
void add_option(char const*& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
|
||||||
void add_option(String& value, char const* help_string, char const* long_name, char short_name, char const* value_name, bool hidden = false);
|
void add_option(String& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
|
||||||
void add_option(StringView& value, char const* help_string, char const* long_name, char short_name, char const* value_name, bool hidden = false);
|
void add_option(StringView& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
|
||||||
void add_option(int& value, char const* help_string, char const* long_name, char short_name, char const* value_name, bool hidden = false);
|
void add_option(int& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
|
||||||
void add_option(unsigned& value, char const* help_string, char const* long_name, char short_name, char const* value_name, bool hidden = false);
|
void add_option(unsigned& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
|
||||||
void add_option(double& value, char const* help_string, char const* long_name, char short_name, char const* value_name, bool hidden = false);
|
void add_option(double& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
|
||||||
void add_option(Optional<double>& value, char const* help_string, char const* long_name, char short_name, char const* value_name, bool hidden = false);
|
void add_option(Optional<double>& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
|
||||||
void add_option(Optional<size_t>& value, char const* help_string, char const* long_name, char short_name, char const* value_name, bool hidden = false);
|
void add_option(Optional<size_t>& value, char const* help_string, char const* long_name, char short_name, char const* value_name, OptionHideMode hide_mode = OptionHideMode::None);
|
||||||
void add_option(Vector<size_t>& values, char const* help_string, char const* long_name, char short_name, char const* value_name, char separator = ',', bool hidden = false);
|
void add_option(Vector<size_t>& values, char const* help_string, char const* long_name, char short_name, char const* value_name, char separator = ',', OptionHideMode hide_mode = OptionHideMode::None);
|
||||||
|
|
||||||
void add_positional_argument(Arg&&);
|
void add_positional_argument(Arg&&);
|
||||||
void add_positional_argument(char const*& value, char const* help_string, char const* name, Required required = Required::Yes);
|
void add_positional_argument(char const*& value, char const* help_string, char const* name, Required required = Required::Yes);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue