Sha256: 37607d4747b60ba0f2365b3f9daff85364df16f5638865426ff1e4d371b6f5ce

Contents?: true

Size: 921 Bytes

Versions: 1

Compression:

Stored size: 921 Bytes

Contents

require 'hscode/version'
require 'hscode/input_parser'
require 'hscode/http_status_codes'
require 'hscode/status_code_types'
require 'optparse'
require 'ostruct'

module Hscode
  class CliController
    def self.call(args)
      options = Hscode::InputParser.new.parse(args)
      print_code(options)
    end

    private_class_method

    def self.print_code(options)
      status_code = HTTP_STATUS_CODES[options.status_code.to_i]

      unless status_code
        puts "#{options.status_code} is not a valid code. See 'hscode --help'."
        exit 1
      end

      PrettyPrint.print(
        "#{options.status_code} - #{status_code[:title]}",
        options.status_code.to_s[0]
      )
      print_description(status_code) if options.verbose
    end

    def self.print_description(status_code)
      status_code[:description].each do |desc|
        PrettyPrint.print("\n#{desc}", '0')
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hscode-0.1.2 lib/hscode.rb