Skip to content

Commit

Permalink
Move to the thor gem
Browse files Browse the repository at this point in the history
  • Loading branch information
dsalahutdinov committed Nov 21, 2018
1 parent b3a7028 commit 7721e66
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 55 deletions.
2 changes: 1 addition & 1 deletion exe/data_integrity
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
require 'bundler/setup'
require 'activerecord/data_integrity'

ActiveRecord::DataIntegrity::CLI.new.run
ActiveRecord::DataIntegrity::CLI.start(ARGV)
21 changes: 16 additions & 5 deletions lib/active_record/data_integrity/cli.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# frozen_string_literal: true

require 'thor'
require_relative 'options'

module ActiveRecord
module DataIntegrity
# CLI application class
class CLI
class CLI < Thor
attr_reader :options

def initialize; end

def run(args = ARGV)
@options = Options.new(args)
desc 'check [OPTIONS]', 'Runs the data integrity check'
method_option :only,
type: :string,
desc: 'List of the rules to check, separated with comma' \
', e.g. --only BelongsTo/ForeignKey,Accordance/PrimaryKey'
def check(_args = ARGV)
@options = Options.new(options)
require_rails

results = cops.map do |cop_class|
Expand All @@ -24,6 +28,13 @@ def run(args = ARGV)

exit(1) if results.include?(false)
end
default_task :check

desc 'version', 'Print the current version'
def version
puts ActiveRecord::DataIntegrity::VERSION
end
map %w[--version -v] => :version

private

Expand Down
12 changes: 4 additions & 8 deletions lib/active_record/data_integrity/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ module ActiveRecord
module DataIntegrity
# Options parser
class Options
def initialize(args)
@options = {}

OptionParser.new do |opts|
opts.on('-o', '--only [COP1,COP2,...]') do |list|
@options[:only] = list.to_s.split(',') if list.present?
end
end.parse(args)
def initialize(options)
@options = {
only: options.only? ? options[:only].to_s.split(',') : nil
}
end

def only
Expand Down
41 changes: 0 additions & 41 deletions spec/lib/active_record/data_integrity/options_spec.rb

This file was deleted.

0 comments on commit 7721e66

Please sign in to comment.