class Samovar::BooleanFlag
Represents a boolean flag with ‘–flag` and `–no-flag` variants.
Public Class Methods
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/flags.rb, line 204 def initialize(text, prefix, value = nil) super(text, prefix) @value = value @negated = @prefix.sub(/^--/, "--no-") @alternatives = [@negated] end
Initialize a new boolean flag.
@parameter text [String] The full flag specification text. @parameter prefix [String] The primary flag prefix (e.g., ‘–flag`). @parameter value [Object | Nil] Reserved for future use.
Calls superclass method
Samovar::Flag::new
Public Instance Methods
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/flags.rb, line 225 def parse(input) if input.first == @prefix input.shift return true elsif input.first == @negated input.shift return false end end
Parse this flag from the input.
@parameter input [Array(String)] The command-line arguments. @returns [Boolean | Nil] True, false, or nil.
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/flags.rb, line 217 def prefix?(token) @prefix == token or @negated == token end
Check if the token matches this flag.
@parameter token [String] The token to check. @returns [Boolean] True if the token matches.