Sha256: 95ea5d3611ff2c38a8ca36c463d5cc4a33935ff55ba0cf7a4faeaf6fcaadcb9b

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

require "thor"
require "yaml"

module CloudstackCli  
  class Base < Thor
    include Thor::Actions
    attr_reader :config

    # catch control-c and exit
    trap("SIGINT") {
      puts " bye"
      exit!
    }

    # exit with return code 1 in case of a error
    def self.exit_on_failure?
      true
    end

    no_commands do  
      def client(opts = {})
        @config ||= CloudstackClient::ConnectionHelper.load_configuration(options[:config])
        @client ||= CloudstackClient::Connection.new(
          @config[:url],
          @config[:api_key],
          @config[:secret_key],
          opts
        )
      end

      def find_project(project_name = options[:project])
        return nil unless project_name
        unless project = client.get_project(project_name)
          say "Project '#{options[:project]}' not found", :red
          exit 1
        end
        project
      end

      def filter_by(objects, tag_name, tag)
        objects.select {|r| r[tag_name].downcase == tag.downcase }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cloudstack-cli-0.2.2 lib/cloudstack-cli/base.rb