Sha256: 9529685ecad41fa06aec0da3aac4c931e916b6e8d8871b13c668883ddc912c77

Contents?: true

Size: 871 Bytes

Versions: 3

Compression:

Stored size: 871 Bytes

Contents

module Warder
  # responsible for executing warder tools
  class CLI
    def initialize(argv, stdin = STDIN, stdout = STDOUT,
                   stderr = STDERR, kernel = Kernel)
      @argv = argv
      @stdin = stdin
      @stdout = stdout
      @stderr = stderr
      @kernel = kernel
    end

    def execute!
      @kernel.exit execute
    end

    private

    def execute
      parse_arguments
      exit_codes = Warder.validators.map do |validator|
        perform_validation(validator)
      end
      exit_codes.compact.inject(0, :+)
    end

    def parse_arguments
      args = Arguments.new(@argv, @stdout, @kernel)
      @options = args.parse
    end

    def perform_validation(validator)
      key = validator::CLI_FULL_OPTION
      return 0 unless @options.send(key)
      runner = validator.new(@stdout, @options)
      runner.perform
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
warder-0.2.1 lib/warder/cli.rb
warder-0.2.0 lib/warder/cli.rb
warder-0.1.9 lib/warder/cli.rb