mirror of
https://git.freebsd.org/ports.git
synced 2025-05-24 23:16:33 -04:00
- Assign maintainership to submitter PR: ports/188289 Submitted by: Michael Moll <kvedulv@kvedulv.de>
69 lines
2.1 KiB
Text
69 lines
2.1 KiB
Text
commit fca42d1a8e9f7a4dfabca0900818e5d355b3b554
|
|
Author: Ivan Nečas <inecas@redhat.com>
|
|
Date: Wed Apr 2 15:08:17 2014 +0200
|
|
|
|
Fixes #5025 - Add support for boolean fields
|
|
|
|
diff --git lib/hammer_cli/output/fields.rb lib/hammer_cli/output/fields.rb
|
|
index 1abe7b2..26b5540 100644
|
|
--- lib/hammer_cli/output/fields.rb
|
|
+++ lib/hammer_cli/output/fields.rb
|
|
@@ -86,4 +86,7 @@ module Fields
|
|
class Collection < ContainerField
|
|
end
|
|
|
|
+ class Boolean < Field
|
|
+ end
|
|
+
|
|
end
|
|
diff --git lib/hammer_cli/output/formatters.rb lib/hammer_cli/output/formatters.rb
|
|
index fa2d299..2d261de 100644
|
|
--- lib/hammer_cli/output/formatters.rb
|
|
+++ lib/hammer_cli/output/formatters.rb
|
|
@@ -144,10 +144,22 @@ module HammerCLI::Output
|
|
end
|
|
end
|
|
|
|
+ class BooleanFormatter < FieldFormatter
|
|
+
|
|
+ def tags
|
|
+ [:flat, :screen]
|
|
+ end
|
|
+
|
|
+ def format(value)
|
|
+ !value || value == "" ? _("no") : _("yes")
|
|
+ end
|
|
+ end
|
|
+
|
|
HammerCLI::Output::Output.register_formatter(DateFormatter.new, :Date)
|
|
HammerCLI::Output::Output.register_formatter(ListFormatter.new, :List)
|
|
HammerCLI::Output::Output.register_formatter(KeyValueFormatter.new, :KeyValue)
|
|
HammerCLI::Output::Output.register_formatter(LongTextFormatter.new, :LongText)
|
|
+ HammerCLI::Output::Output.register_formatter(BooleanFormatter.new, :Boolean)
|
|
|
|
end
|
|
end
|
|
diff --git test/unit/output/formatters_test.rb test/unit/output/formatters_test.rb
|
|
index 2a3a610..050a085 100644
|
|
--- test/unit/output/formatters_test.rb
|
|
+++ test/unit/output/formatters_test.rb
|
|
@@ -138,3 +138,19 @@ describe HammerCLI::Output::Formatters::LongTextFormatter do
|
|
end
|
|
|
|
end
|
|
+
|
|
+describe HammerCLI::Output::Formatters::BooleanFormatter do
|
|
+
|
|
+ it "says yes for true like objects" do
|
|
+ formatter = HammerCLI::Output::Formatters::BooleanFormatter.new
|
|
+ formatter.format(true).must_equal "yes"
|
|
+ formatter.format("yes").must_equal "yes"
|
|
+ end
|
|
+
|
|
+ it "says no for false and nil and empty string" do
|
|
+ formatter = HammerCLI::Output::Formatters::BooleanFormatter.new
|
|
+ formatter.format(nil).must_equal "no"
|
|
+ formatter.format(false).must_equal "no"
|
|
+ formatter.format("").must_equal "no"
|
|
+ end
|
|
+end
|