Skip to content

Commit a098c5e

Browse files
ryanwjacksonpeterfication
authored andcommitted
Additional file patterns cli (ctran#636)
Adds option for additional file patterns (implemented in ctran#633) in the CLI.
1 parent fcfab87 commit a098c5e

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

README.rdoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ you can do so with a simple environment variable, instead of editing the
163163
== Options
164164

165165
Usage: annotate [options] [model_file]*
166+
--additional_file_patterns Additional file paths or globs to annotate
166167
-d, --delete Remove annotations from all model files or the routes.rb file
167168
-p [before|top|after|bottom], Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)
168169
--position
@@ -215,7 +216,6 @@ you can do so with a simple environment variable, instead of editing the
215216
--with-comment include database comments in model annotations
216217

217218

218-
219219
== Sorting
220220

221221
By default, columns will be sorted in database order (i.e. the order in which

lib/annotate/parser.rb

+8
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,18 @@ def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength
4949

5050
option_parser.banner = 'Usage: annotate [options] [model_file]*'
5151

52+
option_parser.on('--additional_file_patterns path1,path2,path3', Array, "Additional file paths or globs to annotate") do |additional_file_patterns|
53+
ENV['additional_file_patterns'] = additional_file_patterns
54+
end
55+
5256
option_parser.on('-d', '--delete', 'Remove annotations from all model files or the routes.rb file') do
5357
@options[:target_action] = :remove_annotations
5458
end
5559

60+
option_parser.on('--additional_file_patterns path1,path2,path3', Array, "Additional file paths or globs to annotate") do |additional_file_patterns|
61+
ENV['additional_file_patterns'] = additional_file_patterns
62+
end
63+
5664
option_parser.on('-p', '--position [before|top|after|bottom]', positions,
5765
'Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)') do |p|
5866
env['position'] = p

lib/tasks/annotate_models.rake

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ task annotate_models: :environment do
1212

1313
options = {is_rake: true}
1414
ENV['position'] = options[:position] = Annotate.fallback(ENV['position'], 'before')
15+
options[:additional_file_patterns] = ENV['additional_file_patterns'] ? ENV['additional_file_patterns'].split(',') : []
1516
options[:position_in_class] = Annotate.fallback(ENV['position_in_class'], ENV['position'])
1617
options[:position_in_fixture] = Annotate.fallback(ENV['position_in_fixture'], ENV['position'])
1718
options[:position_in_factory] = Annotate.fallback(ENV['position_in_factory'], ENV['position'])

spec/annotate/parser_spec.rb

+15
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ module Annotate # rubocop:disable Metrics/ModuleLength
1414
end
1515
end
1616

17+
%w[--additional_file_patterns].each do |option|
18+
describe option do
19+
it 'sets array of paths to :additional_file_patterns' do
20+
# options = "-a ${('foo/bar' 'baz')}"
21+
# Parser.parse(options)
22+
# expect(ENV['additional_file_patterns']).to eq(['foo/bar', 'baz'])
23+
24+
paths = 'foo/bar,baz'
25+
allow(ENV).to receive(:[]=)
26+
Parser.parse([option, paths])
27+
expect(ENV).to have_received(:[]=).with('additional_file_patterns', ['foo/bar', 'baz'])
28+
end
29+
end
30+
end
31+
1732
%w[-d --delete].each do |option|
1833
describe option do
1934
it 'sets target_action to :remove_annotations' do

0 commit comments

Comments
 (0)