Class: Thor::SharedOption

Inherits:
Option show all
Defined in:
lib/thor/parser/shared_option.rb

Overview

A Option that has an additional #groups attribute storing a set of group symbols that the option is a part of.

Direct Known Subclasses

IncludedOption

Constant Summary

Constants inherited from Option

Option::VALID_TYPES

Constants inherited from Argument

Argument::VALID_TYPES

Instance Attribute Summary collapse

Attributes inherited from Option

#aliases, #group, #hide, #lazy_default

Attributes inherited from Argument

#banner, #complete, #default, #description, #enum, #name, #required, #type

Instance Method Summary collapse

Methods inherited from Option

alias_to_switch_name, #all_switch_names, #all_switch_tokens, #dasherize, #dasherized?, #human_name, #long_switch_names, #long_switch_tokens, parse, #short_switch_names, #short_switch_tokens, #switch_name, #undasherize, #usage, #validate!, #validate_default_type!

Methods inherited from Argument

#default_banner, #required?, #show_default?, #usage, #valid_type?, #validate!

Constructor Details

#initialize(name, **options) ⇒ SharedOption

Returns a new instance of SharedOption.



40
41
42
43
44
45
46
47
48
49
# File 'lib/thor/parser/shared_option.rb', line 40

def initialize name, **options
  @groups = Set.new [*options[:groups]].map( &:to_sym )
  
  # # If
  # if options[:group].nil? && groups.count == 1
  #   options[:group] = groups.first.to_s.titleize
  # end
  
  super name, options
end

Instance Attribute Details

#groupsSet<Symbol> (readonly)

Shared option groups this option belongs to.

Returns:

  • (Set<Symbol>)


36
37
38
# File 'lib/thor/parser/shared_option.rb', line 36

def groups
  @groups
end

Instance Method Details

#initialize_optionsObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/thor/parser/shared_option.rb', line 52

def initialize_options
  {
    # {Thor::Argument} options
    desc:               :@description,
    required:           :@required,
    type:               :@type,
    default:            :@default,
    banner:             :@banner,
    eunm:               :@enum,
    
    # {Thor::Option} options
    check_default_type: :@check_default_type,
    lazy_default:       :@lazy_default,
    group:              :@group,
    aliases:            :@aliases,
    hide:               :@hide,
    
    # {Thor::SharedOption} options
    groups:             :@groups,
  }.transform_values &method( :instance_variable_get )
end