Skip to content

Conversation

@andrykonchin
Copy link
Contributor

@andrykonchin andrykonchin commented Nov 15, 2025

Changes:

Supersedes #13726 and closes #13719

yb66 and others added 5 commits August 8, 2023 14:42
…an options.

OptionParser doesn't have --no- and --[no-] options so I added them.

feature: single --no- switch added to OptionParser to set an option to false.
feature: optional --[no-] switch added to OptionParser for true/false options.
style: reformatted some OptionParser regex for readability/comparability.
test: specs for OptionParser boolean options added.
docs: Added docs for `OptionParser#bool` and updated `OptionParser#on`.
@andrykonchin
Copy link
Contributor Author

andrykonchin commented Nov 15, 2025

It seems that this feature is an edge case of type coercion that requires adding some new abstractions. This implementation seems very fast and dirty.

@andrykonchin
Copy link
Contributor Author

I've noticed a minor difference in handling --no-<name> options with Ruby's OptionParser. In Ruby a handler block is called with a false argument. In this PR a block called with "".

@straight-shoota
Copy link
Member

Instead of adding a new handler type, maybe we could just wrap the bool handler in a regular one? We could encode FlagValue::Boolean values as strings "true" and "false".

Handler.new(value_type) do |value|
  block.call(value == "true")
end

This could keep everything a bit simpler, I hope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OptionParser boolean options

4 participants