Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored away the override of to_s, added suppression of output to …
…support --quiet flags and working on the examples for the wiki
- Loading branch information
Showing
10 changed files
with
84 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require 'command_line_reporter' | ||
require 'ostruct' | ||
require 'optparse' | ||
|
||
class Example | ||
include CommandLineReporter | ||
|
||
def initialize | ||
self.formatter = 'progress' | ||
end | ||
|
||
def run(options = {}) | ||
x = 0 | ||
|
||
suppress_output if options.quiet | ||
|
||
report do | ||
10.times do | ||
x += 1 | ||
sleep 0.1 | ||
formatter.progress | ||
end | ||
end | ||
|
||
restore_output if options.quiet | ||
end | ||
end | ||
|
||
|
||
options = OpenStruct.new({:quiet => false}) | ||
|
||
OptionParser.new do |opts| | ||
opts.banner = "Usage: ruby -I lib example/quiet.rb [-q|--quiet]" | ||
|
||
opts.on('-q', '--quiet', 'do not print any output') do | ||
options.quiet = true | ||
end | ||
end.parse! | ||
|
||
Example.new.run(options) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module CommandLineReporter | ||
VERSION = '2.0' | ||
VERSION = '2.1' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ | |
row.add(cols[1]) | ||
t.add(row) | ||
output = capture_stdout { | ||
t.to_s | ||
t.output | ||
} | ||
end | ||
end | ||
|