Commit 8927c88b by Jon Frisby

Make option handling more consistent.

parent 0f04036b
...@@ -64,27 +64,31 @@ Into environment gems from Github checkout: ...@@ -64,27 +64,31 @@ Into environment gems from Github checkout:
(If you used the Gemfile install, prefix the below commands with `bundle exec`.) (If you used the Gemfile install, prefix the below commands with `bundle exec`.)
To annotate all your models, tests, fixtures, etc.: To annotate all your models, tests, fixtures, and factories:
cd /path/to/app cd /path/to/app
annotate annotate
To annotate your models and tests: To annotate your models, tests, and factories:
annotate --exclude fixtures annotate --exclude fixtures
To annotate just your models: To annotate just your models:
annotate --exclude tests,fixtures annotate --exclude tests,fixtures,factories
To annotate routes.rb: To annotate routes.rb:
annotate -r annotate -r
To remove annotations: To remove model/test/fixture/factory annotations:
annotate -d annotate -d
To remove routes.rb annotations:
annotate -r -d
To automatically annotate after running 'rake db:migrate', ensure you've added To automatically annotate after running 'rake db:migrate', ensure you've added
annotate_models to your Rails project's Gemfile, and run this: annotate_models to your Rails project's Gemfile, and run this:
......
...@@ -33,7 +33,6 @@ OptionParser.new do |opts| ...@@ -33,7 +33,6 @@ OptionParser.new do |opts|
end end
end end
ENV['position'] = 'before' # hack: make sure default position is "before"
opts.on('-p', '--position [before|after]', ['before', 'after'], opts.on('-p', '--position [before|after]', ['before', 'after'],
"Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory file(s)") do |p| "Place the annotations at the top (before) or the bottom (after) of the model/test/fixture/factory file(s)") do |p|
ENV['position'] = p ENV['position'] = p
......
...@@ -10,28 +10,27 @@ task :annotate_models => :environment do ...@@ -10,28 +10,27 @@ task :annotate_models => :environment do
require "#{annotate_lib}/annotate/annotate_models" require "#{annotate_lib}/annotate/annotate_models"
require "#{annotate_lib}/annotate/active_record_patch" require "#{annotate_lib}/annotate/active_record_patch"
true_re = /(true|t|yes|y|1)$/i
options={ :is_rake => true } options={ :is_rake => true }
options[:position_in_class] = ENV['position_in_class'] || ENV['position'] || 'before' ENV['position'] = options[:position] = Annotate.fallback(ENV['position'], 'before')
options[:position_in_fixture] = ENV['position_in_fixture'] || ENV['position'] || 'before' options[:position_in_class] = Annotate.fallback(ENV['position_in_class'], ENV['position'])
options[:position_in_factory] = ENV['position_in_factory'] || ENV['position'] || 'before' options[:position_in_fixture] = Annotate.fallback(ENV['position_in_fixture'], ENV['position'])
options[:position_in_test] = ENV['position_in_test'] || ENV['position'] || 'before' options[:position_in_factory] = Annotate.fallback(ENV['position_in_factory'], ENV['position'])
options[:show_indexes] = ENV['show_indexes'] =~ true_re options[:position_in_test] = Annotate.fallback(ENV['position_in_test'], ENV['position'])
options[:simple_indexes] = ENV['simple_indexes'] =~ true_re options[:show_indexes] = Annotate.true?(ENV['show_indexes'])
options[:simple_indexes] = Annotate.true?(ENV['simple_indexes'])
options[:model_dir] = ENV['model_dir'] options[:model_dir] = ENV['model_dir']
options[:include_version] = ENV['include_version'] =~ true_re options[:include_version] = Annotate.true?(ENV['include_version'])
options[:require] = ENV['require'] ? ENV['require'].split(',') : [] options[:require] = ENV['require'] ? ENV['require'].split(',') : []
options[:exclude_tests] = ENV['exclude_tests'] =~ true_re options[:exclude_tests] = Annotate.true?(ENV['exclude_tests'])
options[:exclude_factories] = ENV['exclude_factories'] =~ true_re options[:exclude_factories] = Annotate.true?(ENV['exclude_factories'])
options[:exclude_fixtures] = ENV['exclude_fixtures'] =~ true_re options[:exclude_fixtures] = Annotate.true?(ENV['exclude_fixtures'])
options[:ignore_model_sub_dir] = ENV['ignore_model_sub_dir'] =~ true_re options[:ignore_model_sub_dir] = Annotate.true?(ENV['ignore_model_sub_dir'])
options[:format_bare] = ENV['format_bare'] =~ true_re options[:format_bare] = Annotate.true?(ENV['format_bare'])
options[:format_rdoc] = ENV['format_rdoc'] =~ true_re options[:format_rdoc] = Annotate.true?(ENV['format_rdoc'])
options[:format_markdown] = ENV['format_markdown'] =~ true_re options[:format_markdown] = Annotate.true?(ENV['format_markdown'])
options[:sort] = ENV['sort'] =~ true_re options[:sort] = Annotate.true?(ENV['sort'])
options[:force] = ENV['force'] =~ true_re options[:force] = Annotate.true?(ENV['force'])
options[:trace] = ENV['trace'] =~ true_re options[:trace] = Annotate.true?(ENV['trace'])
AnnotateModels.do_annotations(options) AnnotateModels.do_annotations(options)
end end
...@@ -40,11 +39,9 @@ task :remove_annotation => :environment do ...@@ -40,11 +39,9 @@ task :remove_annotation => :environment do
require "#{annotate_lib}/annotate/annotate_models" require "#{annotate_lib}/annotate/annotate_models"
require "#{annotate_lib}/annotate/active_record_patch" require "#{annotate_lib}/annotate/active_record_patch"
true_re = /(true|t|yes|y|1)$/i
options={ :is_rake => true } options={ :is_rake => true }
options[:model_dir] = ENV['model_dir'] options[:model_dir] = ENV['model_dir']
options[:require] = ENV['require'] ? ENV['require'].split(',') : [] options[:require] = ENV['require'] ? ENV['require'].split(',') : []
options[:trace] = ENV['trace'] =~ true_re options[:trace] = Annotate.true?(ENV['trace'])
AnnotateModels.remove_annotations(options) AnnotateModels.remove_annotations(options)
end end
...@@ -4,7 +4,8 @@ task :annotate_routes => :environment do ...@@ -4,7 +4,8 @@ task :annotate_routes => :environment do
require "#{annotate_lib}/annotate/annotate_routes" require "#{annotate_lib}/annotate/annotate_routes"
options={} options={}
options[:position_in_routes] = ENV['position_in_routes'] || ENV['position'] || 'after' ENV['position'] = options[:position] = Annotate.fallback(ENV['position'], 'before')
options[:position_in_routes] = Annotate.fallback(ENV['position_in_routes'], ENV['position'])
options[:require] = ENV['require'] ? ENV['require'].split(',') : [] options[:require] = ENV['require'] ? ENV['require'].split(',') : []
AnnotateRoutes.do_annotate(options) AnnotateRoutes.do_annotate(options)
end end
......
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