Skip to content

Commit 8947cf5

Browse files
committed
Add additional_file_paths to CLI
1 parent cdd192c commit 8947cf5

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

bin/annotate

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,104 @@ here = File.expand_path(File.dirname __FILE__)
1515
$LOAD_PATH << "#{here}/../lib"
1616

1717
require 'annotate'
18+
<<<<<<< HEAD
1819
require 'annotate/parser'
20+
=======
21+
Annotate.bootstrap_rake
22+
23+
has_set_position = {}
24+
target_action = :do_annotations
25+
positions = %w(before top after bottom)
26+
27+
OptionParser.new do |opts|
28+
opts.banner = 'Usage: annotate [options] [model_file]*'
29+
30+
opts.on('-a', '--additional_file_patterns', Array, "Additional file paths or globs to annotate") do |additional_file_patterns|
31+
ENV['additional_file_patterns'] = additional_file_patterns
32+
end
33+
34+
opts.on('-d', '--delete', 'Remove annotations from all model files or the routes.rb file') do
35+
target_action = :remove_annotations
36+
end
37+
38+
opts.on('-p', '--position [before|top|after|bottom]', positions,
39+
'Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)') do |p|
40+
ENV['position'] = p
41+
%w(position_in_class position_in_factory position_in_fixture position_in_test position_in_routes position_in_serializer).each do |key|
42+
ENV[key] = p unless has_set_position[key]
43+
end
44+
end
45+
46+
opts.on('--pc', '--position-in-class [before|top|after|bottom]', positions,
47+
'Place the annotations at the top (before) or the bottom (after) of the model file') do |p|
48+
ENV['position_in_class'] = p
49+
has_set_position['position_in_class'] = true
50+
end
51+
52+
opts.on('--pf', '--position-in-factory [before|top|after|bottom]', positions,
53+
'Place the annotations at the top (before) or the bottom (after) of any factory files') do |p|
54+
ENV['position_in_factory'] = p
55+
has_set_position['position_in_factory'] = true
56+
end
57+
58+
opts.on('--px', '--position-in-fixture [before|top|after|bottom]', positions,
59+
'Place the annotations at the top (before) or the bottom (after) of any fixture files') do |p|
60+
ENV['position_in_fixture'] = p
61+
has_set_position['position_in_fixture'] = true
62+
end
63+
64+
opts.on('--pt', '--position-in-test [before|top|after|bottom]', positions,
65+
'Place the annotations at the top (before) or the bottom (after) of any test files') do |p|
66+
ENV['position_in_test'] = p
67+
has_set_position['position_in_test'] = true
68+
end
69+
70+
opts.on('--pr', '--position-in-routes [before|top|after|bottom]', positions,
71+
'Place the annotations at the top (before) or the bottom (after) of the routes.rb file') do |p|
72+
ENV['position_in_routes'] = p
73+
has_set_position['position_in_routes'] = true
74+
end
75+
76+
opts.on('--ps', '--position-in-serializer [before|top|after|bottom]', positions,
77+
'Place the annotations at the top (before) or the bottom (after) of the serializer files') do |p|
78+
ENV['position_in_serializer'] = p
79+
has_set_position['position_in_serializer'] = true
80+
end
81+
82+
opts.on('--w', '--wrapper STR', 'Wrap annotation with the text passed as parameter.',
83+
'If --w option is used, the same text will be used as opening and closing') do |p|
84+
ENV['wrapper'] = p
85+
end
86+
87+
opts.on('--wo', '--wrapper-open STR', 'Annotation wrapper opening.') do |p|
88+
ENV['wrapper_open'] = p
89+
end
90+
91+
opts.on('--wc', '--wrapper-close STR', 'Annotation wrapper closing') do |p|
92+
ENV['wrapper_close'] = p
93+
end
94+
95+
opts.on('-r', '--routes', "Annotate routes.rb with the output of 'rake routes'") do
96+
ENV['routes'] = 'true'
97+
end
98+
99+
opts.on('-a', '--active-admin', 'Annotate active_admin models') do
100+
ENV['active_admin'] = 'true'
101+
end
102+
103+
opts.on('-v', '--version', 'Show the current version of this gem') do
104+
puts "annotate v#{Annotate.version}"; exit
105+
end
106+
107+
opts.on('-m', '--show-migration', 'Include the migration version number in the annotation') do
108+
ENV['include_version'] = 'yes'
109+
end
110+
111+
opts.on('-k', '--show-foreign-keys',
112+
"List the table's foreign key constraints in the annotation") do
113+
ENV['show_foreign_keys'] = 'yes'
114+
end
115+
>>>>>>> Add additional_file_paths to CLI
19116

20117
Annotate.bootstrap_rake
21118

lib/annotate/parser.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength
5858
@options[:target_action] = :remove_annotations
5959
end
6060

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

0 commit comments

Comments
 (0)