Skip to content

Commit 3eda6e4

Browse files
committed
Fix option parsing
1 parent 7f9cde6 commit 3eda6e4

File tree

4 files changed

+19
-102
lines changed

4 files changed

+19
-102
lines changed

README.rdoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +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-
-a, --additional_file_paths Additional file paths or globs to annotate
166+
--additional_file_paths Additional file paths or globs to annotate
167167
-d, --delete Remove annotations from all model files or the routes.rb file
168168
-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)
169169
--position

bin/annotate

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

1717
require 'annotate'
18-
<<<<<<< HEAD
1918
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
11619

11720
Annotate.bootstrap_rake
11821

lib/annotate/parser.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,14 @@ 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
5255

5356
option_parser.on('-d', '--delete', 'Remove annotations from all model files or the routes.rb file') do
5457
@options[:target_action] = :remove_annotations
5558
end
5659

57-
option_parser.on('-a', '--additional_file_patterns', Array, "Additional file paths or globs to annotate") do |additional_file_patterns|
58-
ENV['additional_file_patterns'] = additional_file_patterns
59-
end
60-
6160
option_parser.on('-p', '--position [before|top|after|bottom]', positions,
6261
'Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)') do |p|
6362
env['position'] = p

spec/annotate/parser_spec.rb

Lines changed: 15 additions & 0 deletions
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)