From b1245dcd74d3181e2ceef716043a392a9e24b1ec Mon Sep 17 00:00:00 2001 From: Ryan Jackson Date: Thu, 27 Jun 2019 16:17:49 -0700 Subject: [PATCH 01/14] Add option for additional file patterns --- lib/generators/annotate/templates/auto_annotate_models.rake | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/generators/annotate/templates/auto_annotate_models.rake b/lib/generators/annotate/templates/auto_annotate_models.rake index 911c44211..cd29df2b9 100644 --- a/lib/generators/annotate/templates/auto_annotate_models.rake +++ b/lib/generators/annotate/templates/auto_annotate_models.rake @@ -50,7 +50,6 @@ if Rails.env.development? 'wrapper_close' => nil, 'with_comment' => 'true' ) - end Annotate.load_tasks end From 80c03c4f9c2dc1b2d679ed68352b1d4f6fa1cc02 Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 1 Jul 2019 22:06:54 -0700 Subject: [PATCH 02/14] Fix spacing for rubocop --- lib/generators/annotate/templates/auto_annotate_models.rake | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/generators/annotate/templates/auto_annotate_models.rake b/lib/generators/annotate/templates/auto_annotate_models.rake index cd29df2b9..911c44211 100644 --- a/lib/generators/annotate/templates/auto_annotate_models.rake +++ b/lib/generators/annotate/templates/auto_annotate_models.rake @@ -50,6 +50,7 @@ if Rails.env.development? 'wrapper_close' => nil, 'with_comment' => 'true' ) + end Annotate.load_tasks end From 7f9cde60f3690151697b2803520aab9963da5d7e Mon Sep 17 00:00:00 2001 From: Ryan Jackson Date: Wed, 10 Jul 2019 15:37:58 -0400 Subject: [PATCH 03/14] Add additional_file_paths to CLI --- README.rdoc | 1 + bin/annotate | 97 ++++++++++++++++++++++++++++++++++++++++++ lib/annotate/parser.rb | 5 +++ 3 files changed, 103 insertions(+) diff --git a/README.rdoc b/README.rdoc index 0e3c03deb..a5630da51 100644 --- a/README.rdoc +++ b/README.rdoc @@ -163,6 +163,7 @@ you can do so with a simple environment variable, instead of editing the == Options Usage: annotate [options] [model_file]* + -a, --additional_file_paths 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 diff --git a/bin/annotate b/bin/annotate index a27c17515..867e05991 100755 --- a/bin/annotate +++ b/bin/annotate @@ -15,7 +15,104 @@ here = File.expand_path(File.dirname __FILE__) $LOAD_PATH << "#{here}/../lib" require 'annotate' +<<<<<<< HEAD require 'annotate/parser' +======= +Annotate.bootstrap_rake + +has_set_position = {} +target_action = :do_annotations +positions = %w(before top after bottom) + +OptionParser.new do |opts| + opts.banner = 'Usage: annotate [options] [model_file]*' + + opts.on('-a', '--additional_file_patterns', Array, "Additional file paths or globs to annotate") do |additional_file_patterns| + ENV['additional_file_patterns'] = additional_file_patterns + end + + opts.on('-d', '--delete', 'Remove annotations from all model files or the routes.rb file') do + target_action = :remove_annotations + end + + opts.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 + %w(position_in_class position_in_factory position_in_fixture position_in_test position_in_routes position_in_serializer).each do |key| + ENV[key] = p unless has_set_position[key] + end + end + + opts.on('--pc', '--position-in-class [before|top|after|bottom]', positions, + 'Place the annotations at the top (before) or the bottom (after) of the model file') do |p| + ENV['position_in_class'] = p + has_set_position['position_in_class'] = true + end + + opts.on('--pf', '--position-in-factory [before|top|after|bottom]', positions, + 'Place the annotations at the top (before) or the bottom (after) of any factory files') do |p| + ENV['position_in_factory'] = p + has_set_position['position_in_factory'] = true + end + + opts.on('--px', '--position-in-fixture [before|top|after|bottom]', positions, + 'Place the annotations at the top (before) or the bottom (after) of any fixture files') do |p| + ENV['position_in_fixture'] = p + has_set_position['position_in_fixture'] = true + end + + opts.on('--pt', '--position-in-test [before|top|after|bottom]', positions, + 'Place the annotations at the top (before) or the bottom (after) of any test files') do |p| + ENV['position_in_test'] = p + has_set_position['position_in_test'] = true + end + + opts.on('--pr', '--position-in-routes [before|top|after|bottom]', positions, + 'Place the annotations at the top (before) or the bottom (after) of the routes.rb file') do |p| + ENV['position_in_routes'] = p + has_set_position['position_in_routes'] = true + end + + opts.on('--ps', '--position-in-serializer [before|top|after|bottom]', positions, + 'Place the annotations at the top (before) or the bottom (after) of the serializer files') do |p| + ENV['position_in_serializer'] = p + has_set_position['position_in_serializer'] = true + end + + opts.on('--w', '--wrapper STR', 'Wrap annotation with the text passed as parameter.', + 'If --w option is used, the same text will be used as opening and closing') do |p| + ENV['wrapper'] = p + end + + opts.on('--wo', '--wrapper-open STR', 'Annotation wrapper opening.') do |p| + ENV['wrapper_open'] = p + end + + opts.on('--wc', '--wrapper-close STR', 'Annotation wrapper closing') do |p| + ENV['wrapper_close'] = p + end + + opts.on('-r', '--routes', "Annotate routes.rb with the output of 'rake routes'") do + ENV['routes'] = 'true' + end + + opts.on('-a', '--active-admin', 'Annotate active_admin models') do + ENV['active_admin'] = 'true' + end + + opts.on('-v', '--version', 'Show the current version of this gem') do + puts "annotate v#{Annotate.version}"; exit + end + + opts.on('-m', '--show-migration', 'Include the migration version number in the annotation') do + ENV['include_version'] = 'yes' + end + + opts.on('-k', '--show-foreign-keys', + "List the table's foreign key constraints in the annotation") do + ENV['show_foreign_keys'] = 'yes' + end +>>>>>>> Add additional_file_paths to CLI Annotate.bootstrap_rake diff --git a/lib/annotate/parser.rb b/lib/annotate/parser.rb index d728de267..fab5958d2 100644 --- a/lib/annotate/parser.rb +++ b/lib/annotate/parser.rb @@ -49,10 +49,15 @@ def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength option_parser.banner = 'Usage: annotate [options] [model_file]*' + 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('-a', '--additional_file_patterns', 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 From 3eda6e48c6a596d0d77a9685a94137021dd95d4a Mon Sep 17 00:00:00 2001 From: Ryan Jackson Date: Wed, 10 Jul 2019 16:10:39 -0400 Subject: [PATCH 04/14] Fix option parsing --- README.rdoc | 2 +- bin/annotate | 97 ------------------------------------ lib/annotate/parser.rb | 7 ++- spec/annotate/parser_spec.rb | 15 ++++++ 4 files changed, 19 insertions(+), 102 deletions(-) diff --git a/README.rdoc b/README.rdoc index a5630da51..b50ed736e 100644 --- a/README.rdoc +++ b/README.rdoc @@ -163,7 +163,7 @@ you can do so with a simple environment variable, instead of editing the == Options Usage: annotate [options] [model_file]* - -a, --additional_file_paths Additional file paths or globs to annotate + --additional_file_paths 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 diff --git a/bin/annotate b/bin/annotate index 867e05991..a27c17515 100755 --- a/bin/annotate +++ b/bin/annotate @@ -15,104 +15,7 @@ here = File.expand_path(File.dirname __FILE__) $LOAD_PATH << "#{here}/../lib" require 'annotate' -<<<<<<< HEAD require 'annotate/parser' -======= -Annotate.bootstrap_rake - -has_set_position = {} -target_action = :do_annotations -positions = %w(before top after bottom) - -OptionParser.new do |opts| - opts.banner = 'Usage: annotate [options] [model_file]*' - - opts.on('-a', '--additional_file_patterns', Array, "Additional file paths or globs to annotate") do |additional_file_patterns| - ENV['additional_file_patterns'] = additional_file_patterns - end - - opts.on('-d', '--delete', 'Remove annotations from all model files or the routes.rb file') do - target_action = :remove_annotations - end - - opts.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 - %w(position_in_class position_in_factory position_in_fixture position_in_test position_in_routes position_in_serializer).each do |key| - ENV[key] = p unless has_set_position[key] - end - end - - opts.on('--pc', '--position-in-class [before|top|after|bottom]', positions, - 'Place the annotations at the top (before) or the bottom (after) of the model file') do |p| - ENV['position_in_class'] = p - has_set_position['position_in_class'] = true - end - - opts.on('--pf', '--position-in-factory [before|top|after|bottom]', positions, - 'Place the annotations at the top (before) or the bottom (after) of any factory files') do |p| - ENV['position_in_factory'] = p - has_set_position['position_in_factory'] = true - end - - opts.on('--px', '--position-in-fixture [before|top|after|bottom]', positions, - 'Place the annotations at the top (before) or the bottom (after) of any fixture files') do |p| - ENV['position_in_fixture'] = p - has_set_position['position_in_fixture'] = true - end - - opts.on('--pt', '--position-in-test [before|top|after|bottom]', positions, - 'Place the annotations at the top (before) or the bottom (after) of any test files') do |p| - ENV['position_in_test'] = p - has_set_position['position_in_test'] = true - end - - opts.on('--pr', '--position-in-routes [before|top|after|bottom]', positions, - 'Place the annotations at the top (before) or the bottom (after) of the routes.rb file') do |p| - ENV['position_in_routes'] = p - has_set_position['position_in_routes'] = true - end - - opts.on('--ps', '--position-in-serializer [before|top|after|bottom]', positions, - 'Place the annotations at the top (before) or the bottom (after) of the serializer files') do |p| - ENV['position_in_serializer'] = p - has_set_position['position_in_serializer'] = true - end - - opts.on('--w', '--wrapper STR', 'Wrap annotation with the text passed as parameter.', - 'If --w option is used, the same text will be used as opening and closing') do |p| - ENV['wrapper'] = p - end - - opts.on('--wo', '--wrapper-open STR', 'Annotation wrapper opening.') do |p| - ENV['wrapper_open'] = p - end - - opts.on('--wc', '--wrapper-close STR', 'Annotation wrapper closing') do |p| - ENV['wrapper_close'] = p - end - - opts.on('-r', '--routes', "Annotate routes.rb with the output of 'rake routes'") do - ENV['routes'] = 'true' - end - - opts.on('-a', '--active-admin', 'Annotate active_admin models') do - ENV['active_admin'] = 'true' - end - - opts.on('-v', '--version', 'Show the current version of this gem') do - puts "annotate v#{Annotate.version}"; exit - end - - opts.on('-m', '--show-migration', 'Include the migration version number in the annotation') do - ENV['include_version'] = 'yes' - end - - opts.on('-k', '--show-foreign-keys', - "List the table's foreign key constraints in the annotation") do - ENV['show_foreign_keys'] = 'yes' - end ->>>>>>> Add additional_file_paths to CLI Annotate.bootstrap_rake diff --git a/lib/annotate/parser.rb b/lib/annotate/parser.rb index fab5958d2..4f84e0d1d 100644 --- a/lib/annotate/parser.rb +++ b/lib/annotate/parser.rb @@ -49,15 +49,14 @@ 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('-a', '--additional_file_patterns', 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 diff --git a/spec/annotate/parser_spec.rb b/spec/annotate/parser_spec.rb index 467729920..ec8145181 100644 --- a/spec/annotate/parser_spec.rb +++ b/spec/annotate/parser_spec.rb @@ -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 From 45f8b1a726d5aeee3d922667a85a85cee4f94657 Mon Sep 17 00:00:00 2001 From: Ryan Jackson Date: Thu, 11 Jul 2019 11:43:27 -0400 Subject: [PATCH 05/14] Fix options documentation --- README.rdoc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.rdoc b/README.rdoc index b50ed736e..13c0d245d 100644 --- a/README.rdoc +++ b/README.rdoc @@ -163,7 +163,7 @@ you can do so with a simple environment variable, instead of editing the == Options Usage: annotate [options] [model_file]* - --additional_file_paths Additional file paths or globs to annotate + --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 @@ -216,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 From 9c5ac5f1707eefb9b3f7529f4734ab04c7814512 Mon Sep 17 00:00:00 2001 From: Ryan Jackson Date: Thu, 11 Jul 2019 11:47:48 -0400 Subject: [PATCH 06/14] Add missing option default in rake task --- lib/tasks/annotate_models.rake | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/tasks/annotate_models.rake b/lib/tasks/annotate_models.rake index 1d4ab21bc..2e0e38593 100644 --- a/lib/tasks/annotate_models.rake +++ b/lib/tasks/annotate_models.rake @@ -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']) From 489aadd878c4bfdd33a93bb43ad8cf7d504d36aa Mon Sep 17 00:00:00 2001 From: Ryan Jackson Date: Wed, 10 Jul 2019 15:37:58 -0400 Subject: [PATCH 07/14] Add additional_file_paths to CLI --- bin/annotate | 97 ++++++++++++++++++++++++++++++++++++++++++ lib/annotate/parser.rb | 4 ++ 2 files changed, 101 insertions(+) diff --git a/bin/annotate b/bin/annotate index a27c17515..867e05991 100755 --- a/bin/annotate +++ b/bin/annotate @@ -15,7 +15,104 @@ here = File.expand_path(File.dirname __FILE__) $LOAD_PATH << "#{here}/../lib" require 'annotate' +<<<<<<< HEAD require 'annotate/parser' +======= +Annotate.bootstrap_rake + +has_set_position = {} +target_action = :do_annotations +positions = %w(before top after bottom) + +OptionParser.new do |opts| + opts.banner = 'Usage: annotate [options] [model_file]*' + + opts.on('-a', '--additional_file_patterns', Array, "Additional file paths or globs to annotate") do |additional_file_patterns| + ENV['additional_file_patterns'] = additional_file_patterns + end + + opts.on('-d', '--delete', 'Remove annotations from all model files or the routes.rb file') do + target_action = :remove_annotations + end + + opts.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 + %w(position_in_class position_in_factory position_in_fixture position_in_test position_in_routes position_in_serializer).each do |key| + ENV[key] = p unless has_set_position[key] + end + end + + opts.on('--pc', '--position-in-class [before|top|after|bottom]', positions, + 'Place the annotations at the top (before) or the bottom (after) of the model file') do |p| + ENV['position_in_class'] = p + has_set_position['position_in_class'] = true + end + + opts.on('--pf', '--position-in-factory [before|top|after|bottom]', positions, + 'Place the annotations at the top (before) or the bottom (after) of any factory files') do |p| + ENV['position_in_factory'] = p + has_set_position['position_in_factory'] = true + end + + opts.on('--px', '--position-in-fixture [before|top|after|bottom]', positions, + 'Place the annotations at the top (before) or the bottom (after) of any fixture files') do |p| + ENV['position_in_fixture'] = p + has_set_position['position_in_fixture'] = true + end + + opts.on('--pt', '--position-in-test [before|top|after|bottom]', positions, + 'Place the annotations at the top (before) or the bottom (after) of any test files') do |p| + ENV['position_in_test'] = p + has_set_position['position_in_test'] = true + end + + opts.on('--pr', '--position-in-routes [before|top|after|bottom]', positions, + 'Place the annotations at the top (before) or the bottom (after) of the routes.rb file') do |p| + ENV['position_in_routes'] = p + has_set_position['position_in_routes'] = true + end + + opts.on('--ps', '--position-in-serializer [before|top|after|bottom]', positions, + 'Place the annotations at the top (before) or the bottom (after) of the serializer files') do |p| + ENV['position_in_serializer'] = p + has_set_position['position_in_serializer'] = true + end + + opts.on('--w', '--wrapper STR', 'Wrap annotation with the text passed as parameter.', + 'If --w option is used, the same text will be used as opening and closing') do |p| + ENV['wrapper'] = p + end + + opts.on('--wo', '--wrapper-open STR', 'Annotation wrapper opening.') do |p| + ENV['wrapper_open'] = p + end + + opts.on('--wc', '--wrapper-close STR', 'Annotation wrapper closing') do |p| + ENV['wrapper_close'] = p + end + + opts.on('-r', '--routes', "Annotate routes.rb with the output of 'rake routes'") do + ENV['routes'] = 'true' + end + + opts.on('-a', '--active-admin', 'Annotate active_admin models') do + ENV['active_admin'] = 'true' + end + + opts.on('-v', '--version', 'Show the current version of this gem') do + puts "annotate v#{Annotate.version}"; exit + end + + opts.on('-m', '--show-migration', 'Include the migration version number in the annotation') do + ENV['include_version'] = 'yes' + end + + opts.on('-k', '--show-foreign-keys', + "List the table's foreign key constraints in the annotation") do + ENV['show_foreign_keys'] = 'yes' + end +>>>>>>> Add additional_file_paths to CLI Annotate.bootstrap_rake diff --git a/lib/annotate/parser.rb b/lib/annotate/parser.rb index 4f84e0d1d..99abab708 100644 --- a/lib/annotate/parser.rb +++ b/lib/annotate/parser.rb @@ -57,6 +57,10 @@ def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength @options[:target_action] = :remove_annotations end + option_parser.on('-a', '--additional_file_patterns', 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 From 21defa0b9a56b6ba7e7bb5771b9bf22a87a3dd08 Mon Sep 17 00:00:00 2001 From: Ryan Jackson Date: Wed, 10 Jul 2019 16:10:39 -0400 Subject: [PATCH 08/14] Fix option parsing --- bin/annotate | 97 ------------------------------------------ lib/annotate/parser.rb | 4 ++ 2 files changed, 4 insertions(+), 97 deletions(-) diff --git a/bin/annotate b/bin/annotate index 867e05991..a27c17515 100755 --- a/bin/annotate +++ b/bin/annotate @@ -15,104 +15,7 @@ here = File.expand_path(File.dirname __FILE__) $LOAD_PATH << "#{here}/../lib" require 'annotate' -<<<<<<< HEAD require 'annotate/parser' -======= -Annotate.bootstrap_rake - -has_set_position = {} -target_action = :do_annotations -positions = %w(before top after bottom) - -OptionParser.new do |opts| - opts.banner = 'Usage: annotate [options] [model_file]*' - - opts.on('-a', '--additional_file_patterns', Array, "Additional file paths or globs to annotate") do |additional_file_patterns| - ENV['additional_file_patterns'] = additional_file_patterns - end - - opts.on('-d', '--delete', 'Remove annotations from all model files or the routes.rb file') do - target_action = :remove_annotations - end - - opts.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 - %w(position_in_class position_in_factory position_in_fixture position_in_test position_in_routes position_in_serializer).each do |key| - ENV[key] = p unless has_set_position[key] - end - end - - opts.on('--pc', '--position-in-class [before|top|after|bottom]', positions, - 'Place the annotations at the top (before) or the bottom (after) of the model file') do |p| - ENV['position_in_class'] = p - has_set_position['position_in_class'] = true - end - - opts.on('--pf', '--position-in-factory [before|top|after|bottom]', positions, - 'Place the annotations at the top (before) or the bottom (after) of any factory files') do |p| - ENV['position_in_factory'] = p - has_set_position['position_in_factory'] = true - end - - opts.on('--px', '--position-in-fixture [before|top|after|bottom]', positions, - 'Place the annotations at the top (before) or the bottom (after) of any fixture files') do |p| - ENV['position_in_fixture'] = p - has_set_position['position_in_fixture'] = true - end - - opts.on('--pt', '--position-in-test [before|top|after|bottom]', positions, - 'Place the annotations at the top (before) or the bottom (after) of any test files') do |p| - ENV['position_in_test'] = p - has_set_position['position_in_test'] = true - end - - opts.on('--pr', '--position-in-routes [before|top|after|bottom]', positions, - 'Place the annotations at the top (before) or the bottom (after) of the routes.rb file') do |p| - ENV['position_in_routes'] = p - has_set_position['position_in_routes'] = true - end - - opts.on('--ps', '--position-in-serializer [before|top|after|bottom]', positions, - 'Place the annotations at the top (before) or the bottom (after) of the serializer files') do |p| - ENV['position_in_serializer'] = p - has_set_position['position_in_serializer'] = true - end - - opts.on('--w', '--wrapper STR', 'Wrap annotation with the text passed as parameter.', - 'If --w option is used, the same text will be used as opening and closing') do |p| - ENV['wrapper'] = p - end - - opts.on('--wo', '--wrapper-open STR', 'Annotation wrapper opening.') do |p| - ENV['wrapper_open'] = p - end - - opts.on('--wc', '--wrapper-close STR', 'Annotation wrapper closing') do |p| - ENV['wrapper_close'] = p - end - - opts.on('-r', '--routes', "Annotate routes.rb with the output of 'rake routes'") do - ENV['routes'] = 'true' - end - - opts.on('-a', '--active-admin', 'Annotate active_admin models') do - ENV['active_admin'] = 'true' - end - - opts.on('-v', '--version', 'Show the current version of this gem') do - puts "annotate v#{Annotate.version}"; exit - end - - opts.on('-m', '--show-migration', 'Include the migration version number in the annotation') do - ENV['include_version'] = 'yes' - end - - opts.on('-k', '--show-foreign-keys', - "List the table's foreign key constraints in the annotation") do - ENV['show_foreign_keys'] = 'yes' - end ->>>>>>> Add additional_file_paths to CLI Annotate.bootstrap_rake diff --git a/lib/annotate/parser.rb b/lib/annotate/parser.rb index 99abab708..82e355971 100644 --- a/lib/annotate/parser.rb +++ b/lib/annotate/parser.rb @@ -57,6 +57,10 @@ def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength @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('-a', '--additional_file_patterns', Array, "Additional file paths or globs to annotate") do |additional_file_patterns| ENV['additional_file_patterns'] = additional_file_patterns end From 1f2d419b997b3d44ed171212542591d889b6861b Mon Sep 17 00:00:00 2001 From: Ryan Jackson Date: Tue, 6 Aug 2019 11:54:09 +0200 Subject: [PATCH 09/14] Remove duplicate parser --- lib/annotate/parser.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/annotate/parser.rb b/lib/annotate/parser.rb index 82e355971..83554365b 100644 --- a/lib/annotate/parser.rb +++ b/lib/annotate/parser.rb @@ -61,10 +61,6 @@ def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength ENV['additional_file_patterns'] = additional_file_patterns end - option_parser.on('-a', '--additional_file_patterns', 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 From c44293d8bed96248783e723c50f51890e3f0c7d8 Mon Sep 17 00:00:00 2001 From: Ryan Jackson Date: Wed, 10 Jul 2019 15:37:58 -0400 Subject: [PATCH 10/14] Add additional_file_paths to CLI --- bin/annotate | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/bin/annotate b/bin/annotate index a27c17515..867e05991 100755 --- a/bin/annotate +++ b/bin/annotate @@ -15,7 +15,104 @@ here = File.expand_path(File.dirname __FILE__) $LOAD_PATH << "#{here}/../lib" require 'annotate' +<<<<<<< HEAD require 'annotate/parser' +======= +Annotate.bootstrap_rake + +has_set_position = {} +target_action = :do_annotations +positions = %w(before top after bottom) + +OptionParser.new do |opts| + opts.banner = 'Usage: annotate [options] [model_file]*' + + opts.on('-a', '--additional_file_patterns', Array, "Additional file paths or globs to annotate") do |additional_file_patterns| + ENV['additional_file_patterns'] = additional_file_patterns + end + + opts.on('-d', '--delete', 'Remove annotations from all model files or the routes.rb file') do + target_action = :remove_annotations + end + + opts.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 + %w(position_in_class position_in_factory position_in_fixture position_in_test position_in_routes position_in_serializer).each do |key| + ENV[key] = p unless has_set_position[key] + end + end + + opts.on('--pc', '--position-in-class [before|top|after|bottom]', positions, + 'Place the annotations at the top (before) or the bottom (after) of the model file') do |p| + ENV['position_in_class'] = p + has_set_position['position_in_class'] = true + end + + opts.on('--pf', '--position-in-factory [before|top|after|bottom]', positions, + 'Place the annotations at the top (before) or the bottom (after) of any factory files') do |p| + ENV['position_in_factory'] = p + has_set_position['position_in_factory'] = true + end + + opts.on('--px', '--position-in-fixture [before|top|after|bottom]', positions, + 'Place the annotations at the top (before) or the bottom (after) of any fixture files') do |p| + ENV['position_in_fixture'] = p + has_set_position['position_in_fixture'] = true + end + + opts.on('--pt', '--position-in-test [before|top|after|bottom]', positions, + 'Place the annotations at the top (before) or the bottom (after) of any test files') do |p| + ENV['position_in_test'] = p + has_set_position['position_in_test'] = true + end + + opts.on('--pr', '--position-in-routes [before|top|after|bottom]', positions, + 'Place the annotations at the top (before) or the bottom (after) of the routes.rb file') do |p| + ENV['position_in_routes'] = p + has_set_position['position_in_routes'] = true + end + + opts.on('--ps', '--position-in-serializer [before|top|after|bottom]', positions, + 'Place the annotations at the top (before) or the bottom (after) of the serializer files') do |p| + ENV['position_in_serializer'] = p + has_set_position['position_in_serializer'] = true + end + + opts.on('--w', '--wrapper STR', 'Wrap annotation with the text passed as parameter.', + 'If --w option is used, the same text will be used as opening and closing') do |p| + ENV['wrapper'] = p + end + + opts.on('--wo', '--wrapper-open STR', 'Annotation wrapper opening.') do |p| + ENV['wrapper_open'] = p + end + + opts.on('--wc', '--wrapper-close STR', 'Annotation wrapper closing') do |p| + ENV['wrapper_close'] = p + end + + opts.on('-r', '--routes', "Annotate routes.rb with the output of 'rake routes'") do + ENV['routes'] = 'true' + end + + opts.on('-a', '--active-admin', 'Annotate active_admin models') do + ENV['active_admin'] = 'true' + end + + opts.on('-v', '--version', 'Show the current version of this gem') do + puts "annotate v#{Annotate.version}"; exit + end + + opts.on('-m', '--show-migration', 'Include the migration version number in the annotation') do + ENV['include_version'] = 'yes' + end + + opts.on('-k', '--show-foreign-keys', + "List the table's foreign key constraints in the annotation") do + ENV['show_foreign_keys'] = 'yes' + end +>>>>>>> Add additional_file_paths to CLI Annotate.bootstrap_rake From 0632d3466a565a1cf1006ed520dcd84072fa5348 Mon Sep 17 00:00:00 2001 From: Ryan Jackson Date: Wed, 10 Jul 2019 16:10:39 -0400 Subject: [PATCH 11/14] Fix option parsing --- README.rdoc | 2 +- bin/annotate | 97 ---------------------------------------------------- 2 files changed, 1 insertion(+), 98 deletions(-) diff --git a/README.rdoc b/README.rdoc index 13c0d245d..e58adf5de 100644 --- a/README.rdoc +++ b/README.rdoc @@ -163,7 +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 + --additional_file_paths 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 diff --git a/bin/annotate b/bin/annotate index 867e05991..a27c17515 100755 --- a/bin/annotate +++ b/bin/annotate @@ -15,104 +15,7 @@ here = File.expand_path(File.dirname __FILE__) $LOAD_PATH << "#{here}/../lib" require 'annotate' -<<<<<<< HEAD require 'annotate/parser' -======= -Annotate.bootstrap_rake - -has_set_position = {} -target_action = :do_annotations -positions = %w(before top after bottom) - -OptionParser.new do |opts| - opts.banner = 'Usage: annotate [options] [model_file]*' - - opts.on('-a', '--additional_file_patterns', Array, "Additional file paths or globs to annotate") do |additional_file_patterns| - ENV['additional_file_patterns'] = additional_file_patterns - end - - opts.on('-d', '--delete', 'Remove annotations from all model files or the routes.rb file') do - target_action = :remove_annotations - end - - opts.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 - %w(position_in_class position_in_factory position_in_fixture position_in_test position_in_routes position_in_serializer).each do |key| - ENV[key] = p unless has_set_position[key] - end - end - - opts.on('--pc', '--position-in-class [before|top|after|bottom]', positions, - 'Place the annotations at the top (before) or the bottom (after) of the model file') do |p| - ENV['position_in_class'] = p - has_set_position['position_in_class'] = true - end - - opts.on('--pf', '--position-in-factory [before|top|after|bottom]', positions, - 'Place the annotations at the top (before) or the bottom (after) of any factory files') do |p| - ENV['position_in_factory'] = p - has_set_position['position_in_factory'] = true - end - - opts.on('--px', '--position-in-fixture [before|top|after|bottom]', positions, - 'Place the annotations at the top (before) or the bottom (after) of any fixture files') do |p| - ENV['position_in_fixture'] = p - has_set_position['position_in_fixture'] = true - end - - opts.on('--pt', '--position-in-test [before|top|after|bottom]', positions, - 'Place the annotations at the top (before) or the bottom (after) of any test files') do |p| - ENV['position_in_test'] = p - has_set_position['position_in_test'] = true - end - - opts.on('--pr', '--position-in-routes [before|top|after|bottom]', positions, - 'Place the annotations at the top (before) or the bottom (after) of the routes.rb file') do |p| - ENV['position_in_routes'] = p - has_set_position['position_in_routes'] = true - end - - opts.on('--ps', '--position-in-serializer [before|top|after|bottom]', positions, - 'Place the annotations at the top (before) or the bottom (after) of the serializer files') do |p| - ENV['position_in_serializer'] = p - has_set_position['position_in_serializer'] = true - end - - opts.on('--w', '--wrapper STR', 'Wrap annotation with the text passed as parameter.', - 'If --w option is used, the same text will be used as opening and closing') do |p| - ENV['wrapper'] = p - end - - opts.on('--wo', '--wrapper-open STR', 'Annotation wrapper opening.') do |p| - ENV['wrapper_open'] = p - end - - opts.on('--wc', '--wrapper-close STR', 'Annotation wrapper closing') do |p| - ENV['wrapper_close'] = p - end - - opts.on('-r', '--routes', "Annotate routes.rb with the output of 'rake routes'") do - ENV['routes'] = 'true' - end - - opts.on('-a', '--active-admin', 'Annotate active_admin models') do - ENV['active_admin'] = 'true' - end - - opts.on('-v', '--version', 'Show the current version of this gem') do - puts "annotate v#{Annotate.version}"; exit - end - - opts.on('-m', '--show-migration', 'Include the migration version number in the annotation') do - ENV['include_version'] = 'yes' - end - - opts.on('-k', '--show-foreign-keys', - "List the table's foreign key constraints in the annotation") do - ENV['show_foreign_keys'] = 'yes' - end ->>>>>>> Add additional_file_paths to CLI Annotate.bootstrap_rake From 672ca9607a11ee23779d8b1dbdeb012526b5ce09 Mon Sep 17 00:00:00 2001 From: Ryan Jackson Date: Thu, 11 Jul 2019 12:00:01 -0400 Subject: [PATCH 12/14] Add better additional_file_patterns documentation --- README.rdoc | 30 +++++++++++++++++++++++++----- lib/annotate/parser.rb | 2 +- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/README.rdoc b/README.rdoc index e58adf5de..858eaa325 100644 --- a/README.rdoc +++ b/README.rdoc @@ -163,7 +163,7 @@ you can do so with a simple environment variable, instead of editing the == Options Usage: annotate [options] [model_file]* - --additional_file_paths Additional file paths or globs to annotate + --additional_file_patterns Additional file paths or globs to annotate, separated by commas (e.g. `/foo/bar/%model_name%/*.rb,/baz/%model_name%.rb`) -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 @@ -206,15 +206,35 @@ you can do so with a simple environment variable, instead of editing the --frozen Do not allow to change annotations. Exits non-zero if there are going to be changes to files. --timestamp Include timestamp in (routes) annotation --trace If unable to annotate a file, print the full stack trace, not just the exception message. - -I, --ignore-columns REGEX don't annotate columns that match a given REGEX (i.e., `annotate -I '^(id|updated_at|created_at)'` - --ignore-routes REGEX don't annotate routes that match a given REGEX (i.e., `annotate -I '(mobile|resque|pghero)'` + -I, --ignore-columns REGEX don't annotate columns that match a given REGEX (e.g. `annotate -I '^(id|updated_at|created_at)'`) + --ignore-routes REGEX don't annotate routes that match a given REGEX (e.g. `annotate -I '(mobile|resque|pghero)'`)_ --hide-limit-column-types VALUES - don't show limit for given column types, separated by commas (i.e., `integer,boolean,text`) + don't show limit for given column types, separated by commas (e.g. `integer,boolean,text`) --hide-default-column-types VALUES - don't show default for given column types, separated by commas (i.e., `json,jsonb,hstore`) + don't show default for given column types, separated by commas (e.g. `json,jsonb,hstore`) --ignore-unknown-models don't display warnings for bad model files --with-comment include database comments in model annotations +=== Option: +additional_file_patterns+ + +CLI: +--additional_file_patterns+ +Ruby: +:additional_file_patterns+ + +Provide additional paths for the gem to annotate. It works with existing +filename resolutions (options for which can be found in the +resolve_filename+ method of ++annotate_models.rb+). These paths can also include globs. It is recommended to use absolute paths. Here are some +examples: + +- +/app/lib/decorates/%MODEL_NAME%/*.rb+ +- +/app/lib/forms/%PLURALIZED_MODEL_NAME%/**/*.rb+ +- +/app/lib/forms/%TABLE_NAME%/*.rb+ + +The appropriate model will be inferred using the +%*%+ syntax, annotating any matching files. + +When using in a Rails config, you can use the following: + ++File.join(Rails.application.root, 'app/lib/forms/%PLURALIZED_MODEL_NAME%/**/*.rb')+ + == Sorting diff --git a/lib/annotate/parser.rb b/lib/annotate/parser.rb index 83554365b..50de99d6b 100644 --- a/lib/annotate/parser.rb +++ b/lib/annotate/parser.rb @@ -49,7 +49,7 @@ 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| + option_parser.on('--additional_file_patterns path1,path2,path3', Array, "Additional file paths or globs to annotate, separated by commas (e.g. `/foo/bar/%model_name%/*.rb,/baz/%model_name%.rb`)") do |additional_file_patterns| ENV['additional_file_patterns'] = additional_file_patterns end From 974a2077dfedf30bed79b8fee20f8a7f68582f30 Mon Sep 17 00:00:00 2001 From: Ryan Jackson Date: Thu, 11 Jul 2019 15:32:13 -0400 Subject: [PATCH 13/14] Fix formatting --- README.rdoc | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/README.rdoc b/README.rdoc index 858eaa325..785757dd1 100644 --- a/README.rdoc +++ b/README.rdoc @@ -217,23 +217,24 @@ you can do so with a simple environment variable, instead of editing the === Option: +additional_file_patterns+ -CLI: +--additional_file_patterns+ +CLI: +--additional_file_patterns+
Ruby: +:additional_file_patterns+ -Provide additional paths for the gem to annotate. It works with existing -filename resolutions (options for which can be found in the +resolve_filename+ method of -+annotate_models.rb+). These paths can also include globs. It is recommended to use absolute paths. Here are some -examples: +Provide additional paths for the gem to annotate. These paths can include globs. +It is recommended to use absolute paths. Here are some examples: -- +/app/lib/decorates/%MODEL_NAME%/*.rb+ -- +/app/lib/forms/%PLURALIZED_MODEL_NAME%/**/*.rb+ -- +/app/lib/forms/%TABLE_NAME%/*.rb+ -The appropriate model will be inferred using the +%*%+ syntax, annotating any matching files. +- /app/lib/decorates/%MODEL_NAME%/*.rb +- /app/lib/forms/%PLURALIZED_MODEL_NAME%/**/*.rb +- /app/lib/forms/%TABLE_NAME%/*.rb + +The appropriate model will be inferred using the %*% syntax, annotating any matching files. +It works with existing filename resolutions (options for which can be found in the +resolve_filename+ method of ++annotate_models.rb+). When using in a Rails config, you can use the following: -+File.join(Rails.application.root, 'app/lib/forms/%PLURALIZED_MODEL_NAME%/**/*.rb')+ +File.join(Rails.application.root, 'app/lib/forms/%PLURALIZED_MODEL_NAME%/**/*.rb') == Sorting From af55c9dc6d927d8059e1feda1ed5db5b2000af46 Mon Sep 17 00:00:00 2001 From: Ryan Jackson Date: Wed, 24 Jul 2019 02:36:12 +0200 Subject: [PATCH 14/14] Use proper ampersand --- README.rdoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rdoc b/README.rdoc index 785757dd1..b39662553 100644 --- a/README.rdoc +++ b/README.rdoc @@ -224,9 +224,9 @@ Provide additional paths for the gem to annotate. These paths can include globs It is recommended to use absolute paths. Here are some examples: -- /app/lib/decorates/%MODEL_NAME%/*.rb -- /app/lib/forms/%PLURALIZED_MODEL_NAME%/**/*.rb -- /app/lib/forms/%TABLE_NAME%/*.rb +- /app/lib/decorates/%MODEL_NAME%/*.rb +- /app/lib/forms/%PLURALIZED_MODEL_NAME%/**/*.rb +- /app/lib/forms/%TABLE_NAME%/*.rb The appropriate model will be inferred using the %*% syntax, annotating any matching files. It works with existing filename resolutions (options for which can be found in the +resolve_filename+ method of