Sha256: 80ef6684783f5fd7d24846bff265fd0d9ae6eff729fa1dc9544df441d9bf5e65

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

require 'thor'

module Ec2spec
  class CLI < Thor
    desc 'ssh -h host1 ...', 'Compare the specifications of EC2 instances.'
    option 'host', aliases: 'h', type: :array, equired: true
    option 'days', type: :numeric
    option 'rate', type: :numeric
    option 'unit'
    option 'format'
    option 'region'
    option 'app_id'
    option 'calc_type'
    option 'debug', type: :boolean

    # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
    def ssh
      hosts = options['host']
      days = options['days']
      rate = options['rate']
      unit = options['unit']
      app_id = options['app_id']
      calc_type = options['calc_type']
      format = options['format'] || :plain_text
      region = options['region'] || 'ap-northeast-1'

      Ec2spec.logger.level = Logger::DEBUG if options['debug']
      client = Ec2spec::Client.new(hosts, days, format, region)
      if exchange_unit?(unit, rate, app_id)
        client.prepare_price_calculator(unit, rate,
                                        calc_type, app_id)
      end
      puts client.run
    end
    # rubocop:enable Metrics/AbcSize, Metrics/MethodLength

    private

    def exchange_unit?(unit, rate, app_id)
      (rate || app_id) && unit
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ec2spec-0.1.3 lib/ec2spec/cli.rb