Class: Hanami::CLI::Option Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/cli/option.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Command line option

Since:

  • 0.1.0

Direct Known Subclasses

Argument

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Option

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Option

Since:

  • 0.1.0


20
21
22
23
# File 'lib/hanami/cli/option.rb', line 20

def initialize(name, options = {})
  @name = name
  @options = options
end

Instance Attribute Details

#nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0


12
13
14
# File 'lib/hanami/cli/option.rb', line 12

def name
  @name
end

#optionsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0


16
17
18
# File 'lib/hanami/cli/option.rb', line 16

def options
  @options
end

Instance Method Details

#aliasesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0


27
28
29
# File 'lib/hanami/cli/option.rb', line 27

def aliases
  options[:aliases] || []
end

#argument?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 0.1.0


76
77
78
# File 'lib/hanami/cli/option.rb', line 76

def argument?
  false
end

#boolean?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 0.1.0


58
59
60
# File 'lib/hanami/cli/option.rb', line 58

def boolean?
  type == :boolean
end

#defaultObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0


64
65
66
# File 'lib/hanami/cli/option.rb', line 64

def default
  options[:default]
end

#descObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0


33
34
35
36
# File 'lib/hanami/cli/option.rb', line 33

def desc
  desc = options[:desc]
  values ? "#{desc}: (#{values.join('/')})" : desc
end

#description_nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0


70
71
72
# File 'lib/hanami/cli/option.rb', line 70

def description_name
  options[:label] || name.upcase
end

#parser_optionsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength

Since:

  • 0.1.0


85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/hanami/cli/option.rb', line 85

def parser_options
  dasherized_name = Hanami::Utils::String.dasherize(name)
  parser_options  = []

  if type == :boolean
    parser_options << "--[no-]#{dasherized_name}"
  else
    parser_options << "--#{dasherized_name}=#{name}"
    parser_options << "--#{dasherized_name} #{name}"
  end

  parser_options << values if values
  parser_options.unshift(alias_name) unless alias_name.nil?
  parser_options << desc if desc
  parser_options
end

#required?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 0.1.0


40
41
42
# File 'lib/hanami/cli/option.rb', line 40

def required?
  options[:required]
end

#typeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0


46
47
48
# File 'lib/hanami/cli/option.rb', line 46

def type
  options[:type]
end

#valuesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0


52
53
54
# File 'lib/hanami/cli/option.rb', line 52

def values
  options[:values]
end