Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Be more concise in status output when logging/growling and added a si…

…lent mode.

Enable silent mode with `-s' or `--silent', in which case you'll only see real
output when a command failed and only in the terminal.
  • Loading branch information...
commit 5e7deeb01a09e1b69ef17b32ae09b592d3bfd6f4 1 parent 3bf1c54
@alloy alloy authored
View
10 lib/kicker/growl.rb
@@ -32,7 +32,7 @@ def start!
end
def change_occured(command)
- growl(notifications[:change], 'Kicker: Change occured, executing command:', command)
+ growl(notifications[:change], 'Kicker: Executing:', command)
end
def command_callback
@@ -45,12 +45,14 @@ def result(output)
def succeeded(output)
callback = command_callback || DEFAULT_CALLBACK
- growl(notifications[:succeeded], "Kicker: Command succeeded", output, &callback)
+ body = Kicker.silent? ? '' : output
+ growl(notifications[:succeeded], "Kicker: Success", body, &callback)
end
def failed(output)
- message = "Kicker: Command failed (#{Kicker::Utils.last_command_status})"
- growl(notifications[:failed], message, output, &DEFAULT_CALLBACK)
+ message = "Kicker: Failed (#{Kicker::Utils.last_command_status})"
+ body = Kicker.silent? ? '' : output
+ growl(notifications[:failed], message, body, &DEFAULT_CALLBACK)
end
end
end
View
11 lib/kicker/options.rb
@@ -2,11 +2,16 @@
class Kicker
class << self
- attr_accessor :latency, :paths
+ attr_accessor :latency, :paths, :silent
+
+ def silent?
+ @silent
+ end
end
self.latency = 1
self.paths = %w{ . }
+ self.silent = false
module Options
DONT_SHOW_RECIPES = %w{ could_not_handle_file execute_cli_command dot_kick }
@@ -22,6 +27,10 @@ def self.parser
@parser ||= OptionParser.new do |opt|
opt.banner = "Usage: #{$0} [options] [paths to watch]"
+ opt.on('-s', '--silent', 'Keep output to a minimum.') do |silent|
+ Kicker.silent = silent
+ end
+
opt.on('--[no-]growl', 'Whether or not to use Growl. Default is to use growl.') do |growl|
Kicker::Growl.use = growl
end
View
26 lib/kicker/utils.rb
@@ -7,14 +7,9 @@ module Utils #:nodoc:
def execute(command)
@last_command = command
-
- log "Change occured, executing command: #{command}"
- Kicker::Growl.change_occured(command) if Kicker::Growl.use?
-
+ will_execute_command(command)
output = `#{command}`
-
- log_result(output)
- Kicker::Growl.result(output) if Kicker::Growl.use?
+ did_execute_command(output)
end
def last_command
@@ -40,9 +35,20 @@ def last_command_status
private
- def log_result(output)
- output.strip.split("\n").each { |line| log " #{line}" }
- log "Command #{last_command_succeeded? ? 'succeeded' : "failed (#{last_command_status})"}"
+ def will_execute_command(command)
+ log "Executing: #{command}"
+ Kicker::Growl.change_occured(command) if Kicker::Growl.use? && !Kicker.silent?
+ end
+
+ def did_execute_command(output)
+ Kicker::Growl.result(output) if Kicker::Growl.use?
+
+ if last_command_succeeded? && Kicker.silent?
+ log 'Success'
+ else
+ output.strip.split("\n").each { |line| log " #{line}" }
+ log(last_command_succeeded? ? 'Success' : "Failed (#{last_command_status})")
+ end
end
end
end
View
25 test/growl_test.rb
@@ -5,13 +5,17 @@
@growler = Kicker::Growl
end
+ after do
+ Kicker.silent = false
+ end
+
it "should use the default click callback if a command succeeded and no user callback is defined" do
Kicker::Utils.stubs(:last_command_succeeded?).returns(true)
OSX::NSWorkspace.sharedWorkspace.expects(:launchApplication).with('Terminal')
@growler.expects(:growl).with(
@growler.notifications[:succeeded],
- 'Kicker: Command succeeded',
+ 'Kicker: Success',
"line 1\nline 2"
).yields
@@ -25,10 +29,27 @@
OSX::NSWorkspace.sharedWorkspace.expects(:launchApplication).with('Terminal')
@growler.expects(:growl).with(
@growler.notifications[:failed],
- 'Kicker: Command failed (123)',
+ 'Kicker: Failed (123)',
"line 1\nline 2"
).yields
@growler.failed("line 1\nline 2")
end
+
+ it "should only growl that the command succeeded in silent mode" do
+ Kicker.silent = true
+ Kicker::Utils.stubs(:last_command_succeeded?).returns(true)
+
+ @growler.expects(:growl).with(@growler.notifications[:succeeded], 'Kicker: Success', '')
+ @growler.succeeded("line 1\nline 2")
+ end
+
+ it "should only growl that the command failed in silent mode" do
+ Kicker.silent = true
+ Kicker::Utils.stubs(:last_command_succeeded?).returns(false)
+ Kicker::Utils.stubs(:last_command_status).returns(123)
+
+ @growler.expects(:growl).with(@growler.notifications[:failed], 'Kicker: Failed (123)', '')
+ @growler.failed("line 1\nline 2")
+ end
end
View
9 test/options_test.rb
@@ -4,6 +4,7 @@
after do
Kicker.latency = 1
Kicker.paths = %w{ . }
+ Kicker.silent = false
Kicker::Utils.ruby_bin_path = 'ruby'
Kicker::Growl.use = true
Kicker::Growl.command = nil
@@ -29,6 +30,14 @@
Kicker::Growl.should.not.use
end
+ it "should parse if we should keep output to a minimum" do
+ Kicker::Options.parse([])
+ Kicker.should.not.be.silent
+
+ Kicker::Options.parse(%w{ -s })
+ Kicker.should.be.silent
+ end
+
it "should parse the Growl command to use when the user clicks the Growl succeeded message" do
Kicker::Options.parse(%w{ --growl-command ls })
Kicker::Growl.command.should == 'ls'
View
52 test/utils_test.rb
@@ -1,7 +1,10 @@
require File.expand_path('../test_helper', __FILE__)
+Kicker::Utils.send(:public, :did_execute_command)
+
describe "A Kicker instance, concerning its utility methods" do
after do
+ Kicker.silent = false
Kicker::Growl.use = true
end
@@ -19,21 +22,62 @@
utils.stubs(:`).returns("line 1\nline 2")
utils.stubs(:last_command_succeeded?).returns(true)
- utils.expects(:log).with('Change occured, executing command: ls')
+ utils.expects(:log).with('Executing: ls')
utils.expects(:log).with(' line 1')
utils.expects(:log).with(' line 2')
- utils.expects(:log).with('Command succeeded')
+ utils.expects(:log).with('Success')
utils.execute('ls')
utils.stubs(:last_command_succeeded?).returns(false)
utils.stubs(:last_command_status).returns(123)
- utils.expects(:log).with('Change occured, executing command: ls')
+ utils.expects(:log).with('Executing: ls')
utils.expects(:log).with(' line 1')
utils.expects(:log).with(' line 2')
- utils.expects(:log).with('Command failed (123)')
+ utils.expects(:log).with('Failed (123)')
+ utils.execute('ls')
+ end
+
+ it "should growl a change occurred and the output" do
+ utils.stubs(:`).returns("line 1\nline 2")
+ utils.stubs(:last_command_succeeded?).returns(true)
+ utils.stubs(:log)
+
+ Kicker::Growl.expects(:change_occured).with('ls')
+ Kicker::Growl.expects(:result).with("line 1\nline 2")
+ utils.execute('ls')
+ end
+
+ it "should not growl that a change occured in silent mode" do
+ Kicker.silent = true
+ utils.stubs(:did_execute_command)
+
+ utils.expects(:log)
+ Kicker::Growl.expects(:change_occured).never
utils.execute('ls')
end
+
+ it "should only log that is has succeeded in silent mode" do
+ Kicker.silent = true
+ utils.stubs(:last_command_succeeded?).returns(true)
+ Kicker::Growl.expects(:result).with("line 1\nline 2")
+
+ utils.expects(:log).with("Success")
+ utils.did_execute_command("line 1\nline 2")
+ end
+
+ it "should fully log that it has failed in silent mode" do
+ Kicker.silent = true
+ Kicker::Growl.expects(:result).with("line 1\nline 2")
+
+ utils.stubs(:last_command_succeeded?).returns(false)
+ utils.stubs(:last_command_status).returns(123)
+ utils.expects(:log).with(' line 1')
+ utils.expects(:log).with(' line 2')
+ utils.expects(:log).with('Failed (123)')
+ utils.did_execute_command("line 1\nline 2")
+ end
+
it "should store the last executed command" do
Kicker::Growl.use = false
utils.stubs(:log)
Please sign in to comment.
Something went wrong with that request. Please try again.