Sha256: d3db613fd4cc6b6205033d5fd93242cc43165b43bf9c2e19b08d1de58aa00a39

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

module Outliers
  module CLI
    class Resources
      def resources
        @options = {}

        option_parser.parse!

        provider = @options[:provider]

        @logger = Outliers.logger

        unless provider
          @logger.error "Required parameter 'provider' not specified."
          exit 1
        end

        all = Outliers::Resources.collections

        list = all.select { |r| r.to_human =~ /^#{provider}_.*$/ }

        if list.any?
          list.each do |r|
            name = r.to_human
            name.slice! provider
            name[0] = ''
            puts name
            puts "  Verifications:"
            r.verifications.each { |v| puts "    #{v[:name]}(#{v[:args]}) #{v[:description]}" }
            puts "  Filters:"
            r.filters.each { |v| puts "    #{v[:name]}(#{v[:args]}) #{v[:description]}" }
          end
        else
          puts "No resources found for '#{provider}'."
        end
      end

      def command_name
        'resources'
      end

      def command_summary
        'List available resources for a provider.'
      end

      private

      def option_parser
        OptionParser.new do |opts|
          opts.banner = "Usage: outliers resources [options]"

          opts.on("-p", "--provider [PROVIDER]", "Provider to list resources.") do |o|
            @options[:provider] = o
          end
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
outliers-0.2.0 lib/outliers/cli/resources.rb