class Samovar::Flag
Represents a single command-line flag.
A flag can be a simple boolean flag or a flag that accepts a value.
Attributes
Alternative flag prefixes.
@attribute [Array(String) | Nil]
The primary flag prefix.
@attribute [String]
The full flag specification text.
@attribute [String]
Public Class Methods
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/flags.rb, line 94 def initialize(text, prefix, alternatives = nil) @text = text @prefix = prefix @alternatives = alternatives end
Initialize a new flag.
@parameter text [String] The full flag specification text. @parameter prefix [String] The primary flag prefix (e.g., ‘–flag`). @parameter alternatives [Array(String) | Nil] Alternative flag prefixes.
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/flags.rb, line 79 def self.parse(text) if text =~ /(.*?)\s(\<.*?\>)/ ValueFlag.new(text, $1, $2) elsif text =~ /--\[no\]-(.*?)$/ BooleanFlag.new(text, "--#{$1}") else ValueFlag.new(text, text, nil) end end
Parse a flag specification string into a flag instance.
@parameter text [String] The flag specification (e.g., ‘-f <value>` or `–flag`). @returns [Flag] A flag instance (either {ValueFlag} or {BooleanFlag}).
Public Instance Methods
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/flags.rb, line 132 def boolean? false end
Whether this is a boolean flag.
@returns [Boolean] False by default.
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/flags.rb, line 125 def key @key ||= @prefix.sub(/^-*/, "").gsub("-", "_").to_sym end
Generate a key name for this flag.
@returns [Symbol] The key name.
Source
# File vendor/bundle/ruby/3.4.0/gems/samovar-2.4.1/lib/samovar/flags.rb, line 118 def to_s @text end
Generate a string representation for usage output.
@returns [String] The flag text.