Commit 2e076ee5 by Ryan Committed by Andrew W. Lee

Additional file patterns cli (#636)

Adds option for additional file patterns (implemented in #633) in the CLI.
parent f8f1b178
...@@ -163,6 +163,7 @@ you can do so with a simple environment variable, instead of editing the ...@@ -163,6 +163,7 @@ you can do so with a simple environment variable, instead of editing the
== Options == Options
Usage: annotate [options] [model_file]* Usage: annotate [options] [model_file]*
--additional_file_patterns Additional file paths or globs to annotate
-d, --delete Remove annotations from all model files or the routes.rb file -d, --delete Remove annotations from all model files or the routes.rb file
-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) -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)
--position --position
...@@ -215,7 +216,6 @@ you can do so with a simple environment variable, instead of editing the ...@@ -215,7 +216,6 @@ you can do so with a simple environment variable, instead of editing the
--with-comment include database comments in model annotations --with-comment include database comments in model annotations
== Sorting == Sorting
By default, columns will be sorted in database order (i.e. the order in which By default, columns will be sorted in database order (i.e. the order in which
......
...@@ -49,10 +49,18 @@ module Annotate ...@@ -49,10 +49,18 @@ module Annotate
option_parser.banner = 'Usage: annotate [options] [model_file]*' option_parser.banner = 'Usage: annotate [options] [model_file]*'
option_parser.on('--additional_file_patterns path1,path2,path3', Array, "Additional file paths or globs to annotate") do |additional_file_patterns|
ENV['additional_file_patterns'] = additional_file_patterns
end
option_parser.on('-d', '--delete', 'Remove annotations from all model files or the routes.rb file') do option_parser.on('-d', '--delete', 'Remove annotations from all model files or the routes.rb file') do
@options[:target_action] = :remove_annotations @options[:target_action] = :remove_annotations
end end
option_parser.on('--additional_file_patterns path1,path2,path3', Array, "Additional file paths or globs to annotate") do |additional_file_patterns|
ENV['additional_file_patterns'] = additional_file_patterns
end
option_parser.on('-p', '--position [before|top|after|bottom]', positions, option_parser.on('-p', '--position [before|top|after|bottom]', positions,
'Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)') do |p| 'Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory/route/serializer file(s)') do |p|
env['position'] = p env['position'] = p
......
...@@ -12,6 +12,7 @@ task annotate_models: :environment do ...@@ -12,6 +12,7 @@ task annotate_models: :environment do
options = {is_rake: true} options = {is_rake: true}
ENV['position'] = options[:position] = Annotate.fallback(ENV['position'], 'before') ENV['position'] = options[:position] = Annotate.fallback(ENV['position'], 'before')
options[:additional_file_patterns] = ENV['additional_file_patterns'] ? ENV['additional_file_patterns'].split(',') : []
options[:position_in_class] = Annotate.fallback(ENV['position_in_class'], ENV['position']) options[:position_in_class] = Annotate.fallback(ENV['position_in_class'], ENV['position'])
options[:position_in_fixture] = Annotate.fallback(ENV['position_in_fixture'], ENV['position']) options[:position_in_fixture] = Annotate.fallback(ENV['position_in_fixture'], ENV['position'])
options[:position_in_factory] = Annotate.fallback(ENV['position_in_factory'], ENV['position']) options[:position_in_factory] = Annotate.fallback(ENV['position_in_factory'], ENV['position'])
......
...@@ -14,6 +14,21 @@ module Annotate # rubocop:disable Metrics/ModuleLength ...@@ -14,6 +14,21 @@ module Annotate # rubocop:disable Metrics/ModuleLength
end end
end end
%w[--additional_file_patterns].each do |option|
describe option do
it 'sets array of paths to :additional_file_patterns' do
# options = "-a ${('foo/bar' 'baz')}"
# Parser.parse(options)
# expect(ENV['additional_file_patterns']).to eq(['foo/bar', 'baz'])
paths = 'foo/bar,baz'
allow(ENV).to receive(:[]=)
Parser.parse([option, paths])
expect(ENV).to have_received(:[]=).with('additional_file_patterns', ['foo/bar', 'baz'])
end
end
end
%w[-d --delete].each do |option| %w[-d --delete].each do |option|
describe option do describe option do
it 'sets target_action to :remove_annotations' do it 'sets target_action to :remove_annotations' do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment