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

global: add a -q/--quiet flag #87

Merged
merged 2 commits into from
Jan 25, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
62 changes: 45 additions & 17 deletions lib/tugboat/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class CLI < Thor

!check_unknown_options

class_option :quiet, type: :boolean, aliases: "-q"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More of a general question since Ruby 1.9 syntax is being used here: Should we move away from supporting 1.8.7? I believe the latest release of Tugboat still works with 1.8.7.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blom Yea, we probably should, right? What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pearkes Yeah, hopefully most users have moved to 1.9 or higher by now.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this wasn't clear from the readme, please have a note there, it's confusing that you cannot get it to work out of the box in ubuntu 12.04

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bubenkoff Gotcha, to confirm you mean that we should make a note that you must be using > Ruby 1.9?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, sorry if it wasn't clear

On 17 February 2014 17:48, Jack Pearkes [email protected] wrote:

In lib/tugboat/cli.rb:

@@ -9,6 +9,8 @@ class CLI < Thor

 !check_unknown_options
  • class_option :quiet, type: :boolean, aliases: "-q"

@bubenkoff https://github.com/bubenkoff Gotcha, to confirm you mean
that we should make a note that you must be using > Ruby 1.9?

Reply to this email directly or view it on GitHubhttps://github.com//pull/87/files#r9797545
.

Anatoly Bubenkov


map "--version" => :version,
"-v" => :version,
"password-reset" => :password_reset
Expand All @@ -33,7 +35,9 @@ def help(meth=nil)
$USER environment variable.
"
def authorize
Middleware.sequence_authorize.call({})
Middleware.sequence_authorize.call({
"user_quiet" => options[:quiet]
})
end

desc "verify", "Check your DigitalOcean credentials"
Expand All @@ -42,12 +46,16 @@ def authorize
to the API without errors.
"
def verify
Middleware.sequence_verify.call({})
Middleware.sequence_verify.call({
"user_quiet" => options[:quiet]
})
end

desc "droplets", "Retrieve a list of your droplets"
def droplets
Middleware.sequence_list_droplets.call({})
Middleware.sequence_list_droplets.call({
"user_quiet" => options[:quiet]
})
end

desc "images", "Retrieve a list of your images"
Expand All @@ -59,6 +67,7 @@ def droplets
def images
Middleware.sequence_list_images.call({
"user_show_global_images" => options[:global],
"user_quiet" => options[:quiet]
})
end

Expand Down Expand Up @@ -95,7 +104,8 @@ def ssh(name=nil)
"user_droplet_ssh_port" => options[:ssh_port],
"user_droplet_ssh_user" => options[:ssh_user],
"user_droplet_ssh_opts" => options[:ssh_opts],
"user_droplet_ssh_command" => options[:ssh_command]
"user_droplet_ssh_command" => options[:ssh_command],
"user_quiet" => options[:quiet]
})
end

Expand Down Expand Up @@ -133,7 +143,8 @@ def create(name)
"create_droplet_ssh_key_ids" => options[:keys],
"create_droplet_private_networking" => options[:private_networking],
"create_droplet_backups_enabled" => options[:backups_enabled],
"create_droplet_name" => name
"create_droplet_name" => name,
"user_quiet" => options[:quiet]
})
end

Expand All @@ -155,7 +166,8 @@ def destroy(name=nil)
"user_droplet_id" => options[:id],
"user_droplet_name" => options[:name],
"user_confirm_action" => options[:confirm],
"user_droplet_fuzzy_name" => name
"user_droplet_fuzzy_name" => name,
"user_quiet" => options[:quiet]
})
end

Expand All @@ -177,7 +189,8 @@ def restart(name=nil)
"user_droplet_id" => options[:id],
"user_droplet_name" => options[:name],
"user_droplet_hard" => options[:hard],
"user_droplet_fuzzy_name" => name
"user_droplet_fuzzy_name" => name,
"user_quiet" => options[:quiet]
})
end

Expand All @@ -199,7 +212,8 @@ def halt(name=nil)
"user_droplet_id" => options[:id],
"user_droplet_name" => options[:name],
"user_droplet_hard" => options[:hard],
"user_droplet_fuzzy_name" => name
"user_droplet_fuzzy_name" => name,
"user_quiet" => options[:quiet]
})
end

Expand All @@ -216,7 +230,8 @@ def info(name=nil)
Middleware.sequence_info_droplet.call({
"user_droplet_id" => options[:id],
"user_droplet_name" => options[:name],
"user_droplet_fuzzy_name" => name
"user_droplet_fuzzy_name" => name,
"user_quiet" => options[:quiet]
})
end

Expand All @@ -234,7 +249,8 @@ def snapshot(snapshot_name, name=nil)
"user_droplet_id" => options[:id],
"user_droplet_name" => options[:name],
"user_droplet_fuzzy_name" => name,
"user_snapshot_name" => snapshot_name
"user_snapshot_name" => snapshot_name,
"user_quiet" => options[:quiet]
})
end

Expand All @@ -247,7 +263,7 @@ def keys
method_option "key",
:type => :string,
:aliases => "-k",
:desc => "The string of the key"
:desc => "The string of the key"
method_option "path",
:type => :string,
:aliases => "-p",
Expand All @@ -257,12 +273,15 @@ def add_key(name)
"add_key_name" => name,
"add_key_pub_key" => options[:key],
"add_key_file_path" => options[:path],
"user_quiet" => options[:quiet]
})
end

desc "regions", "Show regions"
def regions
Middleware.sequence_regions.call({})
Middleware.sequence_regions.call({
"user_quiet" => options[:quiet]
})
end

desc "version", "Show version"
Expand All @@ -272,7 +291,9 @@ def version

desc "sizes", "Show available droplet sizes"
def sizes
Middleware.sequence_sizes.call({})
Middleware.sequence_sizes.call({
"user_quiet" => options[:quiet]
})
end

desc "start FUZZY_NAME", "Start a droplet"
Expand All @@ -288,7 +309,8 @@ def start(name=nil)
Middleware.sequence_start_droplet.call({
"user_droplet_id" => options[:id],
"user_droplet_name" => options[:name],
"user_droplet_fuzzy_name" => name
"user_droplet_fuzzy_name" => name,
"user_quiet" => options[:quiet]
})
end

Expand All @@ -311,7 +333,8 @@ def resize(name=nil)
"user_droplet_id" => options[:id],
"user_droplet_name" => options[:name],
"user_droplet_size" => options[:size],
"user_droplet_fuzzy_name" => name
"user_droplet_fuzzy_name" => name,
"user_quiet" => options[:quiet]
})
end

Expand All @@ -324,11 +347,13 @@ def resize(name=nil)
:type => :string,
:aliases => "-n",
:desc => "The exact name of the droplet"

def password_reset(name=nil)
Middleware.sequence_password_reset.call({
"user_droplet_id" => options[:id],
"user_droplet_name" => options[:name],
"user_droplet_fuzzy_name" => name
"user_droplet_fuzzy_name" => name,
"user_quiet" => options[:quiet]
})
end

Expand All @@ -346,14 +371,17 @@ def password_reset(name=nil)
:aliases => "-s",
:default => "active",
:desc => "The state of the droplet to wait for"

def wait(name=nil)
Middleware.sequence_wait.call({
"user_droplet_id" => options[:id],
"user_droplet_name" => options[:name],
"user_droplet_desired_state" => options[:state],
"user_droplet_fuzzy_name" => name
"user_droplet_fuzzy_name" => name,
"user_quiet" => options[:quiet]
})
end
end
end


6 changes: 6 additions & 0 deletions lib/tugboat/middleware/check_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def call(env)
exit 1
end

# If the user passes the global `-q/--quiet` flag, redirect
# stdout
if env["user_quiet"] == true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking but I think we can remove == true here as it will be nil when not passed, and it is more idiomatic.

$stdout = File.new('/dev/null', 'w')
end

@app.call(env)
end
end
Expand Down
12 changes: 12 additions & 0 deletions spec/cli/droplets_cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@
Try creating one with \e[32m`tugboat create`\e[0m
eos

expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
end
it "shows no output when --quiet is set" do
stub_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}").
to_return(:status => 200, :body => fixture("show_droplets_empty"))

@cli.options = @cli.options.merge(:quiet => true)
@cli.droplets

# Should be /dev/null not stringIO
expect($stdout).to be_a File

expect(a_request(:get, "https://api.digitalocean.com/droplets?api_key=#{api_key}&client_id=#{client_key}")).to have_been_made
end
end
Expand Down