Class: CodeQuality::CLI::Application
- Inherits:
-
Rake::Application
- Object
- Rake::Application
- CodeQuality::CLI::Application
- Defined in:
- lib/code_quality/cli.rb
Overview
Instance Method Summary collapse
-
#__version ⇒ Object
allow option “–version”.
-
#find_rakefile_location ⇒ Object
allows running ‘code_quality` without a Rakefile.
-
#handle_options ⇒ Object
allow option “–help”.
- #in_namespace(name) ⇒ Object
-
#initialize ⇒ Application
constructor
A new instance of Application.
- #lib_dir ⇒ Object
- #rakefile_path ⇒ Object
- #run ⇒ Object
-
#sort_options(options) ⇒ Object
overwrite options.
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
11 12 13 14 |
# File 'lib/code_quality/cli.rb', line 11 def initialize super @name = "code_quality" end |
Instance Method Details
#__version ⇒ Object
allow option “–version”
74 75 76 77 78 79 80 81 |
# File 'lib/code_quality/cli.rb', line 74 def __version ["--version", "-V", "Display the program version.", lambda do |_value| puts "CodeQuality #{CodeQuality::VERSION}" exit end] end |
#find_rakefile_location ⇒ Object
allows running ‘code_quality` without a Rakefile
84 85 86 87 88 89 90 |
# File 'lib/code_quality/cli.rb', line 84 def find_rakefile_location if (location = super).nil? [rakefile_path, Dir.pwd] else location end end |
#handle_options ⇒ Object
allow option “–help”
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/code_quality/cli.rb', line 36 def .rakelib = ["rakelib"] .trace_output = $stderr OptionParser.new do |opts| opts.separator "Run code_quality for a ruby/rails project, e.g.:" opts.separator " code_quality lowest_score=90 rubocop_max_offenses=100 metrics=stats,rails_best_practices,roodi rails_best_practices_max_offenses=10 roodi_max_offenses=10" opts.separator "" opts.separator "Show available tasks:" opts.separator " code_quality -T" opts.separator "" opts.separator "Invoke an audit task:" opts.separator " code_quality AUDIT_TASK" opts.separator "" opts.separator "Invoke all security audit tasks:" opts.separator " code_quality security_audit" opts.separator "" opts.separator "Invoke all quality audit tasks:" opts.separator " code_quality quality_audit" opts.separator "" opts.separator "Advanced options:" opts.on_tail("-h", "--help", "-H", "Display this help message.") do puts opts exit end .each { |args| opts.on(*args) } opts.environment("RAKEOPT") end.parse! end |
#in_namespace(name) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/code_quality/cli.rb', line 27 def in_namespace(name) if name == @name # remove root namespace yield else super end end |
#lib_dir ⇒ Object
92 93 94 |
# File 'lib/code_quality/cli.rb', line 92 def lib_dir File.("../../../lib", __FILE__) end |
#rakefile_path ⇒ Object
96 97 98 |
# File 'lib/code_quality/cli.rb', line 96 def rakefile_path File.join(lib_dir, "code_quality.rb") end |
#run ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/code_quality/cli.rb', line 16 def run Rake.application = self @rakefiles = [] add_import File.join(lib_dir, "tasks", "code_quality.rake") standard_exception_handling do init name load_rakefile top_level end end |
#sort_options(options) ⇒ Object
overwrite options
69 70 71 |
# File 'lib/code_quality/cli.rb', line 69 def () super.push(__version) end |