Skip to content

Commit 68bdbdb

Browse files
omerrbbulutOmer Bulutpre-commit-ci[bot]
authored
Refactor: route formatter label fallback through internal helper (#1320)
This PR introduces a small internal refactor in `FormatterBase` by routing label fallback through a dedicated helper. There is no behavior change and no public API change: - custom labels set via `label(...)` still take precedence - default behavior remains unchanged This is intended as a small first step toward making future internationalization easier to integrate, as discussed in #1277. --------- Co-authored-by: Omer Bulut <omer.bulut@asisguard.com.tr> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 08e0f7b commit 68bdbdb

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

include/CLI/FormatterFwd.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class FormatterBase {
7171
/// Values are Needs, Excludes, etc.
7272
std::map<std::string, std::string> labels_{};
7373

74+
/// Default user-facing help labels used when no override is set
75+
static std::string default_label(const std::string &key) { return key; }
76+
7477
///@}
7578
/// @name Basic
7679
///@{
@@ -130,9 +133,8 @@ class FormatterBase {
130133

131134
/// Get the current value of a name (REQUIRED, etc.)
132135
CLI11_NODISCARD std::string get_label(std::string key) const {
133-
if(labels_.find(key) == labels_.end())
134-
return key;
135-
return labels_.at(key);
136+
auto it = labels_.find(key);
137+
return it != labels_.end() ? it->second : default_label(key);
136138
}
137139

138140
/// Get the current left column width (options/flags/subcommands)

0 commit comments

Comments
 (0)