Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a sizes command #19

Merged
merged 1 commit into from
Apr 24, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/tugboat/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ def regions
def version
say "Tugboat #{Tugboat::VERSION}"
end

desc "sizes", "Show available droplet sizes"
def sizes
Middleware.sequence_sizes.call({})
end
end
end

11 changes: 11 additions & 0 deletions lib/tugboat/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Middleware
autoload :ListImages, "tugboat/middleware/list_images"
autoload :ListSSHKeys, "tugboat/middleware/list_ssh_keys"
autoload :ListRegions, "tugboat/middleware/list_regions"
autoload :ListSizes, "tugboat/middleware/list_sizes"

# Start the authorization flow.
# This writes a ~/.tugboat file, which can be edited manually.
Expand Down Expand Up @@ -151,5 +152,15 @@ def self.sequence_regions
use ListRegions
end
end

# Display a list of droplet sizes
def self.sequence_sizes
::Middleware::Builder.new do
use InjectConfiguration
use CheckConfiguration
use InjectClient
use ListSizes
end
end
end
end
17 changes: 17 additions & 0 deletions lib/tugboat/middleware/list_sizes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Tugboat
module Middleware
class ListSizes < Base
def call(env)
ocean = env["ocean"]
sizes = ocean.sizes.list.sizes

say "Sizes:"
sizes.each do |size|
say "#{size.name} (id: #{size.id})"
end

@app.call(env)
end
end
end
end
28 changes: 28 additions & 0 deletions spec/cli/sizes_cli_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'spec_helper'

describe Tugboat::CLI do
include_context "spec"

before :each do
@cli = Tugboat::CLI.new
end

describe "sizes" do
it "shows a list" do
stub_request(:get, "https://api.digitalocean.com/sizes?api_key=#{api_key}&client_id=#{client_key}").
to_return(:status => 200, :body => fixture("show_sizes"))

@cli.sizes

expect($stdout.string).to eq <<-eos
Sizes:
Size 1 (id: 1)
Size 2 (id: 2)
Size 3 (id: 3)
eos

expect(a_request(:get, "https://api.digitalocean.com/sizes?api_key=#{api_key}&client_id=#{client_key}")).
to have_been_made
end
end
end
17 changes: 17 additions & 0 deletions spec/fixtures/show_sizes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"status": "OK",
"sizes": [
{
"id": 1,
"name": "Size 1"
},
{
"id": 2,
"name": "Size 2"
},
{
"id": 3,
"name": "Size 3"
}
]
}