Skip to content

Commit

Permalink
New option -q (or --quiet) mutes non-essential CLI output.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinemde committed Nov 9, 2012
1 parent 537b621 commit 10621ee
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 28 deletions.
2 changes: 1 addition & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## NEXT

*
* -q (or --quiet) option mutes non-essential CLI output for all commands.

## v2.0.9 (2012-10-29)

Expand Down
19 changes: 8 additions & 11 deletions lib/engineyard/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def self.start(given_args=ARGV, config={})

class_option :api_token, :type => :string, :desc => "Use API-TOKEN to authenticate this command"
class_option :serverside_version, :type => :string, :desc => "Please use with care! Override deploy system version (same as ENV variable ENGINEYARD_SERVERSIDE_VERSION)"
class_option :quiet, :aliases => %w[-q], :type => :boolean, :desc => "Quieter CLI output."

desc "deploy [--environment ENVIRONMENT] [--ref GIT-REF]",
"Deploy specified branch, tag, or sha to specified environment."
Expand Down Expand Up @@ -152,11 +153,7 @@ def status
app_env = fetch_app_environment(options[:app], options[:environment], options[:account])
deployment = app_env.last_deployment
if deployment
ui.say "# Status of last deployment of #{app_env.hierarchy_name}:"
ui.say "#"
ui.show_deployment(deployment)
ui.say "#"
ui.deployment_result(deployment)
ui.deployment_status(deployment)
else
raise EY::Error, "Application #{app_env.app.name} has not been deployed on #{app_env.environment.name}."
end
Expand Down Expand Up @@ -185,7 +182,7 @@ def environments
if options[:all] && options[:simple]
ui.print_simple_envs api.environments
elsif options[:all]
ui.print_envs(api.apps)
ui.print_envs api.apps
else
remotes = nil
if options[:app] == ''
Expand Down Expand Up @@ -242,7 +239,7 @@ def environments
:desc => "Name of the account in which the environment can be found"
def rebuild
environment = fetch_environment(options[:environment], options[:account])
ui.debug("Rebuilding #{environment.name}")
ui.info "Updating instances on #{environment.hierarchy_name}"
environment.rebuild
end
map "update" => :rebuild
Expand Down Expand Up @@ -271,7 +268,7 @@ def rollback
env_config = config.environment_config(app_env.environment_name)
deploy_config = EY::DeployConfig.new(options, env_config, repo, ui)

ui.info("Rolling back #{app_env.hierarchy_name}")
ui.info "Rolling back #{app_env.hierarchy_name}"

runner = serverside_runner(app_env, deploy_config.verbose)
runner.rollback do |args|
Expand Down Expand Up @@ -371,15 +368,15 @@ def include?(*) true end
def logs
environment = fetch_environment(options[:environment], options[:account])
environment.logs.each do |log|
ui.info log.instance_name
ui.say "Instance: #{log.instance_name}"

if log.main
ui.info "Main logs for #{environment.name}:"
ui.say "Main logs for #{environment.name}:", :green
ui.say log.main
end

if log.custom
ui.info "Custom logs for #{environment.name}:"
ui.say "Custom logs for #{environment.name}:", :green
ui.say log.custom
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/engineyard/cli/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def authenticate
@source = "credentials"
@specified = false

@ui.info("We need to fetch your API token; please log in.")
@ui.info "We need to fetch your API token; please log in."
begin
email = @ui.ask("Email: ")
passwd = @ui.ask("Password: ", true)
Expand Down
18 changes: 15 additions & 3 deletions lib/engineyard/cli/ui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def warn(name, message = nil)
end

def info(name, message = nil)
return if quiet?
say_with_status(name, message, :green)
end

Expand Down Expand Up @@ -156,7 +157,18 @@ def print_envs(apps, default_env_name = nil)
end
end

def deployment_status(deployment)
unless quiet?
say "# Status of last deployment of #{deployment.app_environment.hierarchy_name}:"
say "#"
show_deployment(deployment)
say "#"
end
deployment_result(deployment)
end

def show_deployment(dep)
return if quiet?
output = []
output << ["Account", dep.app.account.name]
output << ["Application", dep.app.name]
Expand All @@ -177,11 +189,11 @@ def show_deployment(dep)

def deployment_result(dep)
if dep.successful?
info 'This deployment was successful.'
say 'Deployment was successful.', :green
elsif dep.finished_at.nil?
warn 'This deployment is not finished.'
say 'Deployment is not finished.', :yellow
else
say_with_status('This deployment failed.', nil, :red)
say 'Deployment failed.', :red
end
end

Expand Down
18 changes: 9 additions & 9 deletions lib/engineyard/deploy_config/migrate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,27 @@ def perform_implied_via_command_in_config
if @perfom.nil? && @command = command_from_config
@perform = true
env_config.migrate = @perform
ui.warn "********************************************************************************"
ui.info "#{env_config.path} config for #{env_config.name} has been updated to"
ui.info "migrate by default to maintain previous expected default behavior."
ui.warn "********************************************************************************"
ui.say "It's a good idea to git commit #{env_config.path} with these new changes."
ui.say "********************************************************************************", :yellow
ui.say "#{env_config.path} config for #{env_config.name} has been updated to"
ui.say "migrate by default to maintain previous expected default behavior."
ui.say ""
ui.say "Please git commit #{env_config.path} with these new changes.", :yellow
ui.say ""
true
else
false
end
end

def perform_from_interaction
ui.warn "Please choose a default migration behavior for this environment."
@perform = ui.agree("Run migrations by default on #{env_config.name}? ", true)
env_config.migrate = @perform
if @perform
command_from_interaction
end
ui.say "#{env_config.path}: migrate settings saved for #{env_config.name}."
ui.say "You can override this default with --migrate or --no-migrate."
ui.info "Please git commit #{env_config.path} with these new changes."
ui.info "#{env_config.path}: migrate settings saved for #{env_config.name}."
ui.info "You can override this default with --migrate or --no-migrate."
ui.say "Please git commit #{env_config.path} with these new changes.", :yellow
true
rescue Timeout::Error
@perform = nil
Expand Down
2 changes: 1 addition & 1 deletion lib/engineyard/thor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def serverside_runner(app_env, verbose, serverside_version = serverside_version,

def use_default_environment
if env = config.default_environment
ui.say "Using default environment #{config.default_environment.inspect} from ey.yml."
ui.info "Using default environment #{config.default_environment.inspect} from ey.yml."
env
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/ey/rebuild_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def command_to_run(opts)
end

def verify_ran(scenario)
@out.should =~ /Rebuilding #{scenario[:environment]}/
@out.should =~ /Updating instances on \w+\/#{scenario[:environment]}/
end

include_examples "it takes an environment name and an account name"
Expand Down
8 changes: 8 additions & 0 deletions spec/ey/ssh_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def extra_ey_options
def command_to_run(opts)
cmd = ["ssh", opts[:ssh_command]].compact + (@ssh_flag || [])
cmd << "--environment" << opts[:environment] if opts[:environment]
cmd << "--quiet" if opts[:quiet]
cmd
end

Expand All @@ -42,6 +43,13 @@ def command_to_run(opts)
end.count.should == @hosts.count
end

it "is quiet" do
login_scenario "one app, one environment"
ey command_to_run(:ssh_command => "ls", :environment => 'giblets', :quiet => true)
@out.should =~ /ssh.*ls/
@out.should_not =~ /Loading application data/
end

it "raises an error when there are no matching hosts" do
login_scenario "one app, one environment, no instances"
ey command_to_run({:ssh_command => "ls", :environment => 'giblets', :verbose => true}), :expect_failure => true
Expand Down
17 changes: 16 additions & 1 deletion spec/ey/status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@
@out.should =~ /Deployed by:\s+One App Many Envs/
@out.should =~ /Started at:/
@out.should =~ /Finished at:/
@out.should =~ /This deployment was successful/
@out.should =~ /Deployment was successful/
end

it "quiets almost all of the output with --quiet" do
fast_ey %w[deploy -e giblets --ref HEAD --no-migrate]
fast_ey %w[status -e giblets -q]
@out.should_not =~ /Application:\s+rails232app/
@out.should_not =~ /Environment:\s+giblets/
@out.should_not =~ /Ref:\s+HEAD/
@out.should_not =~ /Resolved Ref:\s+resolved-HEAD/
@out.should_not =~ /Commit:\s+[a-f0-9]{40}/
@out.should_not =~ /Migrate:\s+false/
@out.should_not =~ /Deployed by:\s+One App Many Envs/
@out.should_not =~ /Started at:/
@out.should_not =~ /Finished at:/
@out.should =~ /Deployment was successful/
end
end

0 comments on commit 10621ee

Please sign in to comment.