tty-option 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,8 +17,11 @@ module TTY
17
17
  # @api public
18
18
  def initialize(**properties, &block)
19
19
  @properties = {}
20
+ @no_command = false
20
21
  properties.each do |key, val|
21
22
  case key.to_sym
23
+ when :command
24
+ key, val = :command, Array(val)
22
25
  when :desc, :description
23
26
  key, val = :desc, [Array(val)]
24
27
  when :header, :footer
@@ -34,8 +37,10 @@ module TTY
34
37
 
35
38
  # Program name for display in help and error messages
36
39
  #
40
+ # @param [String] name
41
+ #
37
42
  # @api public
38
- def program(name = (not_set = true), &block)
43
+ def program(name = (not_set = true))
39
44
  if not_set
40
45
  @properties.fetch(:program) { ::File.basename($0, ".*") }
41
46
  else
@@ -45,6 +50,8 @@ module TTY
45
50
 
46
51
  # Action name for display in help and error messages
47
52
  #
53
+ # @param [Array<String>] values
54
+ #
48
55
  # @api public
49
56
  def command(*values)
50
57
  if values.empty?
@@ -60,15 +67,32 @@ module TTY
60
67
  #
61
68
  # @api public
62
69
  def no_command
70
+ @no_command = true
63
71
  @properties[:command] = []
64
72
  end
65
73
 
74
+ # Whether or not to show command in usage
75
+ #
76
+ # @retrun [Boolean]
77
+ #
78
+ # @api public
79
+ def no_command?
80
+ @no_command
81
+ end
82
+
83
+ # Check for command definition
84
+ #
85
+ # @return [Boolean]
86
+ #
87
+ # @api public
66
88
  def command?
67
89
  @properties.key?(:command) && !@properties[:command].empty?
68
90
  end
69
91
 
70
92
  # Display info before anything else in the usage help
71
93
  #
94
+ # @param [Array<String>] values
95
+ #
72
96
  # @api public
73
97
  def header(*values)
74
98
  if values.empty?
@@ -78,12 +102,19 @@ module TTY
78
102
  end
79
103
  end
80
104
 
105
+ # Whether or not to show header in usage
106
+ #
107
+ # @return [Boolean]
108
+ #
109
+ # @api public
81
110
  def header?
82
111
  @properties.key?(:header) && !@properties[:header].empty?
83
112
  end
84
113
 
85
114
  # Main way to show how all parameters can be used
86
115
  #
116
+ # @param [String] value
117
+ #
87
118
  # @api public
88
119
  def banner(value = (not_set = true))
89
120
  if not_set
@@ -93,12 +124,19 @@ module TTY
93
124
  end
94
125
  end
95
126
 
127
+ # Whether or not to show banner in usage
128
+ #
129
+ # @return [Boolean]
130
+ #
131
+ # @api public
96
132
  def banner?
97
133
  @properties.key?(:banner) && !@properties[:banner].nil?
98
134
  end
99
135
 
100
136
  # Description
101
137
  #
138
+ # @param [Array<String>] values
139
+ #
102
140
  # @api public
103
141
  def desc(*values)
104
142
  if values.empty?
@@ -109,6 +147,11 @@ module TTY
109
147
  end
110
148
  alias description desc
111
149
 
150
+ # Whether or not to show description in usage
151
+ #
152
+ # @return [Boolean]
153
+ #
154
+ # @api public
112
155
  def desc?
113
156
  @properties.key?(:desc) && !@properties[:desc].empty?
114
157
  end
@@ -116,6 +159,8 @@ module TTY
116
159
 
117
160
  # Collects usage examples
118
161
  #
162
+ # @param [Array<String>] values
163
+ #
119
164
  # @api public
120
165
  def example(*values)
121
166
  if values.empty?
@@ -126,6 +171,11 @@ module TTY
126
171
  end
127
172
  alias examples example
128
173
 
174
+ # Whether or not to show example in usage
175
+ #
176
+ # @return [Boolean]
177
+ #
178
+ # @api public
129
179
  def example?
130
180
  @properties.key?(:example) && !@properties[:example].empty?
131
181
  end
@@ -133,6 +183,8 @@ module TTY
133
183
 
134
184
  # Display info after everyting else in the usage help
135
185
  #
186
+ # @param [Array<String>] values
187
+ #
136
188
  # @api public
137
189
  def footer(*values)
138
190
  if values.empty?
@@ -142,6 +194,11 @@ module TTY
142
194
  end
143
195
  end
144
196
 
197
+ # Whether or not to show footer in usage
198
+ #
199
+ # @return [Boolean]
200
+ #
201
+ # @api public
145
202
  def footer?
146
203
  @properties.key?(:footer) && !@properties[:footer].empty?
147
204
  end
@@ -14,13 +14,14 @@ module TTY
14
14
  def wrap(text, width: 80, indent: 2, indent_first: false)
15
15
  wrap = width - indent
16
16
  lines = []
17
+ indentation = " " * indent
17
18
 
18
19
  line, rest = *next_line(text, wrap: wrap)
19
- lines << (indent_first ? " " * indent : "") + line
20
+ lines << (indent_first ? indentation : "") + line
20
21
 
21
22
  while !rest.nil?
22
23
  line, rest = *next_line(rest, wrap: wrap)
23
- lines << " " * indent + line.strip
24
+ lines << indentation + line.strip
24
25
  end
25
26
 
26
27
  lines.join("\n")
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TTY
4
4
  module Option
5
- VERSION = "0.1.0"
5
+ VERSION = "0.3.0"
6
6
  end # Option
7
7
  end # TTY
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tty-option
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Murach
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-18 00:00:00.000000000 Z
11
+ date: 2023-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -55,6 +55,7 @@ files:
55
55
  - lib/tty-option.rb
56
56
  - lib/tty/option.rb
57
57
  - lib/tty/option/aggregate_errors.rb
58
+ - lib/tty/option/const.rb
58
59
  - lib/tty/option/conversions.rb
59
60
  - lib/tty/option/converter.rb
60
61
  - lib/tty/option/deep_dup.rb
@@ -99,8 +100,9 @@ metadata:
99
100
  changelog_uri: https://github.com/piotrmurach/tty-option/blob/master/CHANGELOG.md
100
101
  documentation_uri: https://www.rubydoc.info/gems/tty-option
101
102
  homepage_uri: https://ttytoolkit.org
103
+ rubygems_mfa_required: 'true'
102
104
  source_code_uri: https://github.com/piotrmurach/tty-option
103
- post_install_message:
105
+ post_install_message:
104
106
  rdoc_options: []
105
107
  require_paths:
106
108
  - lib
@@ -116,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
118
  version: '0'
117
119
  requirements: []
118
120
  rubygems_version: 3.1.2
119
- signing_key:
121
+ signing_key:
120
122
  specification_version: 4
121
- summary: An intuitive and flexible command line parser
123
+ summary: An intuitive and flexible command line parser.
122
124
  test_files: []