Class: Clip::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/clip.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(short, long, options) ⇒ Option

Returns a new instance of Option.



344
345
346
347
348
349
350
351
# File 'lib/clip.rb', line 344

def initialize(short, long, options)
  @short = short
  @long = long
  @description = options[:desc] || ""
  @default = options[:default]
  @required = options[:required]
  @multi = options[:multi]
end

Instance Attribute Details

#defaultObject

Returns the value of attribute default.



342
343
344
# File 'lib/clip.rb', line 342

def default
  @default
end

#descriptionObject

Returns the value of attribute description.



342
343
344
# File 'lib/clip.rb', line 342

def description
  @description
end

#longObject

Returns the value of attribute long.



342
343
344
# File 'lib/clip.rb', line 342

def long
  @long
end

#multiObject

Returns the value of attribute multi.



342
343
344
# File 'lib/clip.rb', line 342

def multi
  @multi
end

#requiredObject

Returns the value of attribute required.



342
343
344
# File 'lib/clip.rb', line 342

def required
  @required
end

#shortObject

Returns the value of attribute short.



342
343
344
# File 'lib/clip.rb', line 342

def short
  @short
end

Instance Method Details

#has_default?Boolean

Returns:

  • (Boolean)


367
368
369
# File 'lib/clip.rb', line 367

def has_default?
  not @default.nil?
end

#multi?Boolean

Returns:

  • (Boolean)


371
372
373
# File 'lib/clip.rb', line 371

def multi?
  @multi == true
end

#process(parser, value) ⇒ Object



353
354
355
356
357
358
359
360
361
# File 'lib/clip.rb', line 353

def process(parser, value)
  if @multi
    current = parser.send(@long) || []
    current.concat(value.split(','))
    parser.send("#{@long}=".to_sym, current)
  else
    parser.send("#{@long}=".to_sym, value)
  end
end

#required?Boolean

Returns:

  • (Boolean)


363
364
365
# File 'lib/clip.rb', line 363

def required?
  @required == true
end

#usageObject



375
376
377
378
379
380
381
382
383
# File 'lib/clip.rb', line 375

def usage
  out = sprintf('-%-2s --%-10s %s',
                @short,
                @long.to_s.gsub('_', '-').to_sym,
                @description)
  out << " (defaults to '#{@default}')" if @default
  out << " REQUIRED" if @required
  out
end