Sha256: 58a2ec9525af679c16874761936635a9f58c95892832d4f2a040c9abad750e78

Contents?: true

Size: 1.75 KB

Versions: 6

Compression:

Stored size: 1.75 KB

Contents

require 'rubygems'
require 'interact'
require 'terminal-table/import'

module VMC::Cli

  module Command

    class Base
      include Interactive
      disable_rewind

      attr_reader :no_prompt, :prompt_ok

      def initialize(options={})
        @options = options.dup
        @no_prompt = @options[:noprompts]
        @prompt_ok = !no_prompt

        # Suppress colorize on Windows systems for now.
        if WINDOWS
          VMC::Cli::Config.colorize = false
        end
      end

      # Inject a client to help in testing.
      def client(cli=nil)
        @client ||= cli
        return @client if @client
        @client = VMC::Client.new(target_url, auth_token)
        @client.trace = VMC::Cli::Config.trace if VMC::Cli::Config.trace
        @client.proxy_for @options[:proxy] if @options[:proxy]
        @client
      end

      def client_info
        @client_info ||= client.info
      end

      def target_url
        @target_url ||= VMC::Cli::Config.target_url
      end

      def target_base
        @target_base ||= VMC::Cli::Config.suggest_url
      end

      def auth_token
        @auth_token ||= VMC::Cli::Config.auth_token
      end

      def runtimes_info
        return @runtimes if @runtimes
        info = client_info
        @runtimes = {}
        if info[:frameworks]
          info[:frameworks].each_value do |f|
            next unless f[:runtimes]
            f[:runtimes].each { |r| @runtimes[r[:name]] = r}
          end
        end
        @runtimes
      end

      def frameworks_info
        return @frameworks if @frameworks
        info = client_info
        @frameworks = []
        if info[:frameworks]
          info[:frameworks].each_value { |f| @frameworks << [f[:name]] }
        end
        @frameworks
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
vmc-0.3.15 lib/cli/commands/base.rb
vmc-0.3.15.beta.1 lib/cli/commands/base.rb
vmc-0.3.14 lib/cli/commands/base.rb
vmc-0.3.14.beta.4 lib/cli/commands/base.rb
vmc-0.3.14.beta.3 lib/cli/commands/base.rb
vmc-0.3.13 lib/cli/commands/base.rb