Sha256: 33761e709a84de4501f6f0fb00866091b3eb7e1deba5bd7c48e18f5f05ffb1ea

Contents?: true

Size: 1.15 KB

Versions: 10

Compression:

Stored size: 1.15 KB

Contents

require "active_support"
require "active_support/core_ext"

module CC
  module CLI
    class Runner
      def self.run(argv)
        new(argv).run
      rescue => ex
        $stderr.puts("error: (#{ex.class}) #{ex.message}")

        CLI.debug("backtrace: #{ex.backtrace.join("\n\t")}")
      end

      def initialize(args)
        @args = args
      end

      def run
        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
        @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
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
codeclimate-0.52.0 lib/cc/cli/runner.rb
codeclimate-0.51.3 lib/cc/cli/runner.rb
codeclimate-0.51.2 lib/cc/cli/runner.rb
codeclimate-0.51.1 lib/cc/cli/runner.rb
codeclimate-0.51.0 lib/cc/cli/runner.rb
codeclimate-0.50.0 lib/cc/cli/runner.rb
codeclimate-0.49.0 lib/cc/cli/runner.rb
codeclimate-0.48.0 lib/cc/cli/runner.rb
codeclimate-0.47.0 lib/cc/cli/runner.rb
codeclimate-0.46.0 lib/cc/cli/runner.rb