Sha256: a2dedce338de28c31677f63d976c141350e01eac25ec2df53dd972795bf604b3

Contents?: true

Size: 2 KB

Versions: 16

Compression:

Stored size: 2 KB

Contents

#!/usr/bin/env ruby

require 'rubygems'
require 'roo_on_rails/config'

module RooOnRails
  module CLI
    class Base
      attr_reader :argv

      def initialize(argv)
        @argv = argv
      end

      def usage
        raise NotImplementedError
      end

      protected

      def _log(message)
        $stderr.puts message
      end

      def _assert_argv_length(range)
        return if range.include?(argv.length)
        _log 'Wrong number of arguments.'
        _log "Usage: #{usage}"
        exit 1
      end
    end

    class Sidekiq < Base
      def usage
        'roo_on_rails sidekiq'
      end

      def run
        _assert_argv_length(0..0)
        require 'roo_on_rails/sidekiq/loader'
        RooOnRails::Sidekiq::Loader.run
      end
    end

    class Harness < Base
      def usage
        'roo_on_rails harness [-f|--fix]'
      end

      def run
        _parser.parse!(argv)
        _assert_argv_length(0..0)
        require 'roo_on_rails/harness'
        RooOnRails::Harness.new(try_fix: _options[:fix], context: Config.load).run
      end

      private

      def _options
        @options ||= { fix: false, env: nil }
      end

      def _parser
        require 'optionparser'

        OptionParser.new do |o|
          o.banner = usage

          o.on('-f', '--fix', 'Attempt to fix failed checks') do
            _options[:fix] = true
          end

          o.on('-e', '--env', 'Application environments to check (comma-separated)') do |v|
            _options[:env] = v
          end
        end
      end
    end

    class Toplevel < Base
      def usage
        'roo_on_rails [sidekiq|harness] [options]'
      end

      def run
        case argv.first
        when 'sidekiq' then
          argv.shift
          Sidekiq.new(argv).run
        when 'harness', nil then
          argv.shift
          Harness.new(argv).run
        else
          _log 'Incorrect arguments.'
          _log "Usage: #{usage}"
          exit 1
        end
      end
    end
  end
end

RooOnRails::CLI::Toplevel.new(ARGV).run

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
roo_on_rails-1.22.0 exe/roo_on_rails
roo_on_rails-1.21.0 exe/roo_on_rails
roo_on_rails-1.20.0 exe/roo_on_rails
roo_on_rails-1.19.0 exe/roo_on_rails
roo_on_rails-1.18.0 exe/roo_on_rails
roo_on_rails-1.17.0 exe/roo_on_rails
roo_on_rails-1.16.2 exe/roo_on_rails
roo_on_rails-1.16.1 exe/roo_on_rails
roo_on_rails-1.16.0 exe/roo_on_rails
roo_on_rails-1.15.0 exe/roo_on_rails
roo_on_rails-1.14.0 exe/roo_on_rails
roo_on_rails-1.13.1 exe/roo_on_rails
roo_on_rails-1.13.0 exe/roo_on_rails
roo_on_rails-1.12.0 exe/roo_on_rails
roo_on_rails-1.11.1 exe/roo_on_rails
roo_on_rails-1.11.0 exe/roo_on_rails