class Samovar::ValueFlag
Represents a flag that accepts a value or acts as a boolean.
Attributes
Alternative flag prefixes.
@attribute [Array(String)]
The value placeholder.
@attribute [String | Nil]
Public Class Methods
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/flags.rb, line 144 def initialize(text, prefix, value) super(text, prefix) @value = value *@alternatives, @prefix = @prefix.split("/") end
Initialize a new value flag.
@parameter text [String] The full flag specification text. @parameter prefix [String] The primary flag prefix with alternatives (e.g., ‘-f/–flag`). @parameter value [String | Nil] The value placeholder (e.g., `<file>`).
Samovar::Flag::new
Public Instance Methods
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/flags.rb, line 165 def boolean? @value.nil? end
Whether this is a boolean flag (no value required).
@returns [Boolean] True if no value is required.
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/flags.rb, line 181 def parse(input) if prefix?(input.first) # Whether we are expecting to parse a value from input: if @value # Get the actual value from input: flag, value = input.shift(2) return value else # Otherwise, we are just a boolean flag: input.shift return key end end end
Parse this flag from the input.
@parameter input [Array(String)] The command-line arguments. @returns [String | Symbol | Nil] The parsed value.
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/flags.rb, line 173 def prefix?(token) @prefix == token or @alternatives.include?(token) end
Check if the token matches this flag.
@parameter token [String] The token to check. @returns [Boolean] True if the token matches.