15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
# File 'lib/tailor/cli/options.rb', line 15
def self.parse!(args)
register_custom_option_types
options = OpenStruct.new
options.config_file = ''
options.output_file = ''
options.formatters = []
options.show_config = false
options.style = {}
opts = OptionParser.new do |opt|
opt.banner = self.banner
opt.separator ''
opt.separator ' ' + ('-' * 73)
opt.separator ''
opt.separator 'Config file options:'
opt.on('-s', '--show-config', 'Show your current config.') do
options.show_config = true
end
opt.on('-c', '--config-file FILE',
'Use a specific config file.') do |config|
options.config_file = config
end
opt.on('-o', '--output-file FILE',
'Print result in a output file if using the proper formatter.') do |output|
options.output_file = output
end
opt.on('--create-config', 'Create a new .tailor file') do
if create_config
msg = 'Your new tailor config file was created at '
msg << "#{Dir.pwd}/.tailor"
$stdout.puts msg
exit
else
$stderr.puts 'Creation of .tailor failed!'
exit 1
end
end
opt.separator ''
opt.separator 'Style Options:'
opt.separator " (Any option that doesn't have an explicit way of"
opt.separator ' turning it off can be done so simply by passing'
opt.separator " passing it 'false'.)"
opt.separator ''
opt.separator ' * Horizontal Spacing:'
opt.on('--allow-conditional-parentheses BOOL',
'Check for conditionals wrapped in parentheses? (default: true)') do |c|
options.style[:allow_conditional_parentheses] = c
end
opt.on('--allow-hard-tabs BOOL',
'Check for hard tabs? (default: true)') do |c|
options.style[:allow_hard_tabs] = c
end
opt.on('--allow-trailing-line-spaces BOOL',
'Check for trailing spaces at the end of lines?',
'(default: true)') do |c|
options.style[:allow_trailing_line_spaces] = c
end
opt.on('--allow-unnecessary-interpolation BOOL',
'Check for unnecessary interpolation in strings?',
'(default: false)') do |c|
options.style[:allow_unnecessary_interpolation] = c
end
opt.on('--allow-unnecessary-double-quotes BOOL',
'Check for unnecessary use of double quotes?',
'(default: false)') do |c|
options.style[:allow_unnecessary_double_quotes] = c
end
opt.on('--indentation-spaces NUMBER', INTEGER_OR_OFF,
'Spaces to expect indentation. (default: 2)') do |c|
options.style[:indentation_spaces] = c
end
opt.on('--max-line-length NUMBER', INTEGER_OR_OFF,
'Max characters in a line. (default: 80)') do |c|
options.style[:max_line_length] = c
end
opt.on('--spaces-after-comma NUMBER', INTEGER_OR_OFF,
'Spaces to expect after a comma. (default: 1)') do |c|
options.style[:spaces_after_comma] = c
end
opt.on('--spaces-before-comma NUMBER', INTEGER_OR_OFF,
'Spaces to expect before a comma. (default: 0)') do |c|
options.style[:spaces_before_comma] = c
end
opt.on('--spaces-after-conditional NUMBER', INTEGER_OR_OFF,
'Spaces to expect after a conditional. (default: 1)') do |c|
options.style[:spaces_after_conditional] = c
end
opt.on('--spaces-after-lbrace NUMBER', INTEGER_OR_OFF,
'Spaces to expect after a {. (default: 1)') do |c|
options.style[:spaces_after_lbrace] = c
end
opt.on('--spaces-before-lbrace NUMBER', INTEGER_OR_OFF,
'Spaces to expect before a {. (default: 1)') do |c|
options.style[:spaces_before_lbrace] = c
end
opt.on('--spaces-before-rbrace NUMBER', INTEGER_OR_OFF,
'Spaces to expect before a }. (default: 1)') do |c|
options.style[:spaces_before_rbrace] = c
end
opt.on('--spaces-in-empty-braces NUMBER', INTEGER_OR_OFF,
'Spaces to expect between a { and }. (default: 0)') do |c|
options.style[:spaces_in_empty_braces] = c
end
opt.on('--spaces-after-lbracket NUMBER', INTEGER_OR_OFF,
'Spaces to expect after a [. (default: 0)') do |c|
options.style[:spaces_after_lbracket] = c
end
opt.on('--spaces-before-rbracket NUMBER', INTEGER_OR_OFF,
'Spaces to expect before a ]. (default: 0)') do |c|
options.style[:spaces_before_rbracket] = c
end
opt.on('--spaces-after-lparen NUMBER', INTEGER_OR_OFF,
'Spaces to expect after a (. (default: 0)') do |c|
options.style[:spaces_after_lparen] = c
end
opt.on('--spaces-before-rparen NUMBER', INTEGER_OR_OFF,
'Spaces to expect before a ). (default: 0)') do |c|
options.style[:spaces_before_rparen] = c
end
opt.separator ''
opt.separator ''
opt.separator ' * Naming:'
opt.on('--allow-camel-case-methods BOOL',
'Check for camel-case method names?', '(default: true)') do |c|
options.style[:allow_camel_case_methods] = instance_eval(c)
end
opt.on('--allow-screaming-snake-case-classes BOOL',
'Check for classes like "My_Class"?', '(default: true)') do |c|
options.style[:allow_screaming_snake_case_classes] =
instance_eval(c)
end
opt.separator ''
opt.separator ''
opt.separator ' * Vertical Spacing'
opt.on('--max-code-lines-in-class NUMBER', INTEGER_OR_OFF,
'Max number lines of code in a class.', '(default: 300)') do |c|
options.style[:max_code_lines_in_class] = c
end
opt.on('--max-code-lines-in-method NUMBER', INTEGER_OR_OFF,
'Max number lines of code in a method.', '(default: 30)') do |c|
options.style[:max_code_lines_in_method] = c
end
opt.on('--trailing-newlines NUMBER', INTEGER_OR_OFF,
'Newlines to expect at the end of the file.', '(default: 1)') do |c|
options.style[:trailing_newlines] = c
end
opt.separator ''
opt.separator 'Common options:'
=begin
opt.on('-f', '--format FORMATTER') do |format|
options.formatters << format
end
=end
opt.on('--[no-]color', 'Output in color') do |color|
@output_color = color
end
opt.on_tail('-v', '--version', 'Show the version') do
puts version
exit
end
opt.on_tail('-d', '--debug', 'Turn on debug logging') do
Tailor::Logger.log = true
end
opt.on_tail('-h', '--help', 'Show this message') do |_|
puts opt
exit
end
end
opts.parse!(args)
colorize
options
end
|