Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional file patterns cli #636

Merged
merged 9 commits into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ you can do so with a simple environment variable, instead of editing the
== Options

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
-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
Expand Down Expand Up @@ -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



== Sorting

By default, columns will be sorted in database order (i.e. the order in which
Expand Down
8 changes: 8 additions & 0 deletions lib/annotate/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,18 @@ def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength

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
@options[:target_action] = :remove_annotations
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,
'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
Expand Down
1 change: 1 addition & 0 deletions lib/tasks/annotate_models.rake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ task annotate_models: :environment do

options = {is_rake: true}
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_fixture] = Annotate.fallback(ENV['position_in_fixture'], ENV['position'])
options[:position_in_factory] = Annotate.fallback(ENV['position_in_factory'], ENV['position'])
Expand Down
15 changes: 15 additions & 0 deletions spec/annotate/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ module Annotate # rubocop:disable Metrics/ModuleLength
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|
describe option do
it 'sets target_action to :remove_annotations' do
Expand Down