Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArgsParser: Allow applications to override version string #25534

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Userland/Libraries/LibCore/ArgsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,16 @@ void ArgsParser::print_usage_markdown(FILE* file, StringView argv0)

void ArgsParser::print_version(FILE* file)
{
// FIXME: Allow applications to override version string for --version.
// Especially useful for Lagom applications
outln(file, Core::Version::read_long_version_string().release_value_but_fixme_should_propagate_errors());
if (m_version != ""sv)
outln(file, m_version);
else
outln(file, Core::Version::read_long_version_string().release_value_but_fixme_should_propagate_errors());
}

void ArgsParser::set_version(StringView const& version)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regardless of the other ongoing discussion, it might be worth thinking about if we want some owning string type here instead.

{
VERIFY(version != ""sv);
m_version = version;
}

void ArgsParser::add_option(Option&& option)
Expand Down
3 changes: 3 additions & 0 deletions Userland/Libraries/LibCore/ArgsParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class ArgsParser {
void print_usage_terminal(FILE*, StringView argv0);
void print_usage_markdown(FILE*, StringView argv0);
void print_version(FILE*);
void set_version(StringView const& version);

void add_option(Option&&);
void add_ignored(char const* long_name, char short_name = 0, OptionHideMode hide_mode = OptionHideMode::None);
Expand Down Expand Up @@ -213,6 +214,8 @@ class ArgsParser {
bool m_perform_autocomplete { false };
char const* m_general_help { nullptr };
bool m_stop_on_first_non_option { false };

StringView m_version;
};

}
Loading