Sha256: 42ef190ceb6ee88a31a2b345ac56b0ce967fa19b2357ace5dd6364225fdac220

Contents?: true

Size: 1.07 KB

Versions: 38

Compression:

Stored size: 1.07 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
        CLI.const_get(command_name)
      rescue NameError
        nil
      end

      def command_name
        case command
        when nil, "-h", "-?", "--help" then "Help"
        when "-v", "--version" then "Version"
        else command.sub(":", "::").underscore.camelize
        end
      end

      def command_arguments
        @args[1..-1]
      end

      def command
        @args.first
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
codeclimate-0.45.0 lib/cc/cli/runner.rb
codeclimate-0.44.0 lib/cc/cli/runner.rb
codeclimate-0.43.1 lib/cc/cli/runner.rb
codeclimate-0.43.0 lib/cc/cli/runner.rb
codeclimate-0.42.1 lib/cc/cli/runner.rb
codeclimate-0.42.0 lib/cc/cli/runner.rb
codeclimate-0.41.0 lib/cc/cli/runner.rb
codeclimate-0.40.3 lib/cc/cli/runner.rb
codeclimate-0.40.2 lib/cc/cli/runner.rb
codeclimate-0.40.1 lib/cc/cli/runner.rb
codeclimate-0.40.0 lib/cc/cli/runner.rb
codeclimate-0.39.0 lib/cc/cli/runner.rb
codeclimate-0.38.1 lib/cc/cli/runner.rb
codeclimate-0.38.0 lib/cc/cli/runner.rb
codeclimate-0.37.0 lib/cc/cli/runner.rb
codeclimate-0.36.0 lib/cc/cli/runner.rb
codeclimate-0.35.2 lib/cc/cli/runner.rb
codeclimate-0.35.1 lib/cc/cli/runner.rb
codeclimate-0.35.0 lib/cc/cli/runner.rb
codeclimate-0.34.1 lib/cc/cli/runner.rb