Sha256: aa5de55da46f45962da72dd9e0cda8a3ecf31a8ce737cca07cadb62f0f8c7b89

Contents?: true

Size: 1.43 KB

Versions: 97

Compression:

Stored size: 1.43 KB

Contents

require "active_support"
require "active_support/core_ext"
require "cc/cli/version_checker"

module CC
  module CLI
    class Runner
      def self.run(argv)
        new(argv).run
      rescue => ex
        $stderr.puts("error: (#{ex.class}) #{ex.message}")
        CLI.logger.debug("backtrace: #{ex.backtrace.join("\n\t")}")
        exit 1
      end

      def initialize(args)
        @args = args
      end

      def run
        VersionChecker.new.check if check_version?

        if command_class
          command = command_class.new(command_arguments)
          command.execute
        else
          command_not_found
        end
      end

      def command_not_found
        $stderr.puts "unknown command #{command}"
        exit 1
      end

      def command_class
        command_const = Command[command]
        if command_const.abstract?
          nil
        else
          command_const
        end
      rescue NameError
        nil
      end

      def command_arguments
        Array(@args[1..-1])
      end

      def command
        command_name = @args.first
        case command_name
        when nil, "-h", "-?", "--help"
          "help"
        when "-v", "--version"
          "version"
        else
          command_name
        end
      end

      private

      def check_version?
        if ARGV.first == "--no-check-version"
          ARGV.shift
          false
        else
          true
        end
      end
    end
  end
end

Version data entries

97 entries across 97 versions & 2 rubygems

Version Path
codeclimate-fede-0.85.38 lib/cc/cli/runner.rb
codeclimate-fede-0.85.37 lib/cc/cli/runner.rb
codeclimate-fede-0.85.36 lib/cc/cli/runner.rb
codeclimate-fede-0.85.35 lib/cc/cli/runner.rb
codeclimate-fede-0.85.33 lib/cc/cli/runner.rb
codeclimate-fede-0.85.32 lib/cc/cli/runner.rb
codeclimate-fede-0.85.31 lib/cc/cli/runner.rb
codeclimate-fede-0.85.30 lib/cc/cli/runner.rb
codeclimate-fede-0.85.21 lib/cc/cli/runner.rb
codeclimate-fede-0.85.24 lib/cc/cli/runner.rb
codeclimate-fede-0.85.23 lib/cc/cli/runner.rb
codeclimate-0.85.23 lib/cc/cli/runner.rb
codeclimate-0.85.22 lib/cc/cli/runner.rb
codeclimate-0.85.21 lib/cc/cli/runner.rb
codeclimate-0.85.19 lib/cc/cli/runner.rb
codeclimate-0.85.18 lib/cc/cli/runner.rb
codeclimate-0.85.17 lib/cc/cli/runner.rb
codeclimate-0.85.15 lib/cc/cli/runner.rb
codeclimate-0.85.14 lib/cc/cli/runner.rb
codeclimate-0.85.13 lib/cc/cli/runner.rb