Skip to content

Commit

Permalink
min_api is specified in rest_client call
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Harris committed Apr 15, 2013
1 parent f84661d commit 7456742
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
7 changes: 3 additions & 4 deletions lib/rhc/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def parse_options_and_call_procs *args
end

# Separate option lists with '--'
remaining = args.split('--').map{ |a| opts.parse!(a) }.inject([]) do |arr, sub|
remaining = args.split('--').map{ |a| opts.parse!(a) }.inject([]) do |arr, sub|
arr << '--' unless arr.empty?
arr.concat(sub)
end
Expand Down Expand Up @@ -151,7 +151,7 @@ def self.deprecated!
instance = Commander::Runner.instance
command_name = instance.command_name_from_args
command = instance.active_command

if new_cmd = command.deprecated(command_name)
new_cmd = "rhc #{command.name}" if new_cmd == true
RHC::Helpers.deprecated_command new_cmd
Expand Down Expand Up @@ -225,7 +225,6 @@ def self.to_commander(instance=Commander::Runner.instance)
cmd = opts[:class].new
cmd.options = options
cmd.config = config
cmd.min_api = opts[:min_api]

args = fill_arguments(cmd, options, args_metadata, options_metadata, args)
needs_configuration!(cmd, options, config)
Expand Down Expand Up @@ -282,7 +281,7 @@ def self.fill_arguments(cmd, options, args_metadata, options_metadata, args)
value = cmd.send(context_helper) if value.nil? and context_helper

if value.nil?
value =
value =
if arg[:arg_type] == :list
all = []
while available.first && available.first != '--'
Expand Down
17 changes: 6 additions & 11 deletions lib/rhc/commands/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
class RHC::Commands::Base

attr_writer :options, :config
attr_accessor :min_api

def initialize(options=Commander::Command::Options.new,
config=RHC::Config.new)
Expand All @@ -34,14 +33,14 @@ def rest_client(opts={})
auth = RHC::Auth::Basic.new(options)
auth = RHC::Auth::Token.new(options, auth, token_store) if (options.use_authorization_tokens || options.token) && !(options.rhlogin && options.password)
debug "Authenticating with #{auth.class}"
client = client_from_options(:auth => auth)

if client && min_api.to_f > client.api_version_negotiated.to_f
raise RHC::ServerAPINotSupportedException.new(min_api, client.api_version_negotiated)
end
client_from_options(:auth => auth)
end

client
if opts[:min_api] && opts[:min_api].to_f > @rest_client.api_version_negotiated.to_f
raise RHC::ServerAPINotSupportedException.new(opts[:min_api], @rest_client.api_version_negotiated)
end

@rest_client
end

def token_store
Expand Down Expand Up @@ -110,10 +109,6 @@ def self.suppress_wizard
@suppress_wizard = true
end

def self.minimum_api(value)
options[:min_api] = value
end

def self.suppress_wizard?
@suppress_wizard
end
Expand Down
11 changes: 5 additions & 6 deletions lib/rhc/commands/cartridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Cartridge < Base
description <<-DESC
Cartridges add functionality to OpenShift applications. Each application
has one web cartridge to listen for HTTP requests, and any number
of addon cartridges. Addons may include databases like MySQL and Mongo,
of addon cartridges. Addons may include databases like MySQL and Mongo,
administrative tools like phpMyAdmin, or build clients like Jenkins.
Most cartridges that listen for incoming network traffic are placed on
Expand All @@ -17,7 +17,7 @@ class Cartridge < Base
(like Jenkins) or provide environment variables.
Use the 'cartridges' command to see a list of all available cartridges.
Add a new cartridge to your application with 'add-cartridge'.
Add a new cartridge to your application with 'add-cartridge'.
For scalable applications, use the 'cartridge-scale' command on the web
cartridge to set the minimum and maximum scale.
Expand All @@ -36,10 +36,10 @@ def list
carts = rest_client.cartridges.sort_by{ |c| "#{c.type == 'standalone' && 1}_#{c.tags.include?('experimental') ? 1 : 0}_#{(c.display_name || c.name).downcase}" }

pager

if options.verbose
carts.each do |c|
paragraph do
paragraph do
name = c.display_name != c.name && "#{color(c.display_name, :cyan)} [#{c.name}]" || c.name
tags = c.tags - RHC::Rest::Cartridge::HIDDEN_TAGS
say header([name, "(#{c.only_in_new? ? 'web' : 'addon'})"])
Expand Down Expand Up @@ -216,10 +216,9 @@ def scale(cartridge)
option ["--remove amount"], "Remove the indicated amount from the additional storage capacity"
option ["--set amount"], "Set the specified amount of additional storage capacity"
option ["-f", "--force"], "Force the action"
minimum_api 1.3
def storage(cartridge)
cartridges = Array(cartridge)
rest_app = rest_client.find_application(options.namespace, options.app, :include => :cartridges)
rest_app = rest_client(:min_api => 1.3).find_application(options.namespace, options.app, :include => :cartridges)

# Pull the desired action
#
Expand Down

0 comments on commit 7456742

Please sign in to comment.