Sha256: 11f1379ae013c73cff4ba124da3bc94ce1d5e5bf21c9aab9562cb0071839e14d

Contents?: true

Size: 1.41 KB

Versions: 18

Compression:

Stored size: 1.41 KB

Contents

module ThreeScaleToolbox
  module Command
    def self.included(base)
      base.extend(ClassMethods)
    end

    module ClassMethods
      def subcommands
        @subcommands ||= []
      end

      def add_subcommand(command)
        subcommands << command
      end

      ##
      # Override to command
      #
      def command
        raise Exception, 'base command has no command definition'
      end

      ##
      # Iterate recursively over command tree
      #
      def build_command
        subcommands.each_with_object(command) do |subcommand, root_command|
          root_command.add_command(subcommand.build_command)
        end
      end
    end

    def config
      @config ||= ThreeScaleToolbox::Configuration.new(config_file)
    end

    def config_file
      options[:'config-file']
    end

    def remotes
      @remotes ||= Remotes.new(config)
    end

    ##
    # Input param can be endpoint url or remote name
    #
    def threescale_client(str)
      ThreeScaleClientFactory.get(remotes, str, verify_ssl, verbose)
    end

    def verify_ssl
      # this is flag. It is either true or false. Cannot be nil
      !options[:insecure]
    end

    def verbose
      options[:verbose]
    end

    def exit_with_message(message)
      raise ThreeScaleToolbox::Error, message
    end

    def fetch_required_option(key)
      options.fetch(key) { exit_with_message "error: Missing argument #{key}" }
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
3scale_toolbox-0.19.3 lib/3scale_toolbox/base_command.rb
3scale_toolbox-0.19.2 lib/3scale_toolbox/base_command.rb
3scale_toolbox-0.19.1 lib/3scale_toolbox/base_command.rb
3scale_toolbox-0.19.0 lib/3scale_toolbox/base_command.rb
3scale_toolbox-0.18.3 lib/3scale_toolbox/base_command.rb
3scale_toolbox-0.18.2 lib/3scale_toolbox/base_command.rb
3scale_toolbox-0.18.0 lib/3scale_toolbox/base_command.rb
3scale_toolbox-0.17.1 lib/3scale_toolbox/base_command.rb
3scale_toolbox-0.17.0 lib/3scale_toolbox/base_command.rb
3scale_toolbox-0.16.0 lib/3scale_toolbox/base_command.rb
3scale_toolbox-0.15.0 lib/3scale_toolbox/base_command.rb
3scale_toolbox-0.14.0 lib/3scale_toolbox/base_command.rb
3scale_toolbox-0.13.0 lib/3scale_toolbox/base_command.rb
3scale_toolbox-0.12.4 lib/3scale_toolbox/base_command.rb
3scale_toolbox-0.12.3 lib/3scale_toolbox/base_command.rb
3scale_toolbox-0.12.2 lib/3scale_toolbox/base_command.rb
3scale_toolbox-0.11.0 lib/3scale_toolbox/base_command.rb
3scale_toolbox-0.10.0 lib/3scale_toolbox/base_command.rb