Skip to content

Add rfl::cli::KeepEmptyItems to read empty list items as missing values - #32

Open
clockblocker wants to merge 1 commit into
wave-base-10from
cli-keep-empty-items
Open

clockblocker wants to merge 1 commit into
wave-base-10from
cli-keep-empty-items

Conversation

@clockblocker

@clockblocker clockblocker commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds the opt-in rfl::cli::KeepEmptyItems processor so empty items in split CLI lists (--tags=a,,b) are preserved as missing elements instead of silently dropped.

Example

// Input: --tags=a,,b   with rfl::cli::read<Config, rfl::cli::KeepEmptyItems>(...)
Field type Result
std::vector<std::optional<std::string>> {"a", std::nullopt, "b"}
std::vector<rfl::DefaultVal<std::string>> {"a", "", "b"}
std::vector<std::shared_ptr<std::string>> {"a", nullptr, "b"}
std::vector<std::string> / std::vector<int> Failed to parse field 'tags': Empty item at index 1.

Key details

  • Default behavior (skip empty items) is unchanged when omitted; ignored by non-CLI formats.
  • Applies only to split lists: combining ListDelimiter<""> with KeepEmptyItems is a compile-time static_assert.
  • --tags= is still an empty list; whitespace (" ") is a non-empty item; repeated options and list positionals report the combined index in rfl::Error::details().
  • Docs updated in cli.md ("Empty list items").

(Same rfl::cli::Settings vs processor API question as #30.)

AI-authored. Depends on: #26, #30, #36.

@clockblocker
clockblocker changed the base branch from wave-base-7 to wave-base-10 November 14, 2026 13:01
@clockblocker
clockblocker force-pushed the wave-base-10 branch 2 times, most recently from 30b4ec4 to b06e850 Compare November 16, 2026 05:18
@clockblocker
clockblocker force-pushed the cli-keep-empty-items branch 2 times, most recently from 9b492a6 to fb28a2e Compare November 17, 2026 04:36
@clockblocker
clockblocker force-pushed the cli-keep-empty-items branch 3 times, most recently from 9d84085 to dcc0f15 Compare November 17, 2026 07:15
rfl::cli skips empty items in split lists, so `--tags=a,,b` is read as
[a, b]. With rfl::cli::KeepEmptyItems, each empty item is kept as a
missing value at its index, and the element type decides, as it does for
a missing field: std::optional<T> elements become std::nullopt,
rfl::DefaultVal<T> elements become T{}, smart pointers become null, and
types that need a value fail with "Empty item at index 1.",
located at ["tags", 1] in rfl::Error::details(). The index counts the
items of every occurrence of a repeated option or list positional.

The setting only applies to lists that are split: with
ListDelimiter<"">, every occurrence is one item as it is, even if it is
empty, so combining the two is a compile-time error.

The Reader keeps empty pieces when splitting and passes each one on as
a variable without a value. A Parser specialization for DefaultVal with
the CLI reader returns the default for it, and one for std::wstring
rejects it, as ParserWString would otherwise read it as "". Without the
setting, nothing changes, and other formats ignore it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant