Skip to content

Commit

Permalink
Fixes #15257 - let print adapters decide whether to paginate
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas Strachota committed Jun 9, 2016
1 parent def5d03 commit 7904f9a
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config/cli_config.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Enable interactive queries?
:interactive: true
# Number of records listed per page
:per_page: 20
# :per_page: 20
# Location of shell history file
:history_file: '~/.hammer/history'

Expand Down
5 changes: 5 additions & 0 deletions lib/hammer_cli/output/adapter/abstract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ def tags
def initialize(context={}, formatters={})
@context = context
@formatters = HammerCLI::Output::Formatters::FormatterLibrary.new(filter_formatters(formatters))
@paginate_by_default = true
end

def paginate_by_default?
!!@paginate_by_default
end

def print_message(msg, msg_params={})
Expand Down
5 changes: 5 additions & 0 deletions lib/hammer_cli/output/adapter/csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ def is_id?
end
end

def initialize(context={}, formatters={})
super
@paginate_by_default = false
end

def tags
[:flat]
end
Expand Down
5 changes: 5 additions & 0 deletions lib/hammer_cli/output/adapter/tree_structure.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
module HammerCLI::Output::Adapter
class TreeStructure < Abstract

def initialize(context={}, formatters={})
super
@paginate_by_default = false
end

def prepare_collection(fields, collection)
collection.map do |element|
render_fields(fields, element)
Expand Down
2 changes: 1 addition & 1 deletion lib/hammer_cli/output/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def self.register_formatter(formatter, *field_types)

def init_adapter(adapter_name)
raise NameError unless self.class.adapters.has_key? adapter_name
self.class.adapters[adapter_name].new(context, self.class.formatters)
@adapter ||= self.class.adapters[adapter_name].new(context, self.class.formatters)
end

end
Expand Down
4 changes: 4 additions & 0 deletions test/unit/output/adapter/abstract_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def tags
end
end

it "allows default pagination" do
adapter.paginate_by_default?.must_equal true
end

it "should filter formatters with incompatible tags" do

HammerCLI::Output::Formatters::FormatterLibrary.expects(:new).with({ :type => [] })
Expand Down
4 changes: 4 additions & 0 deletions test/unit/output/adapter/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
let(:context) {{}}
let(:adapter) { HammerCLI::Output::Adapter::Base.new(context, HammerCLI::Output::Output.formatters) }

it "allows default pagination" do
adapter.paginate_by_default?.must_equal true
end

context "print_collection" do

let(:id) { Fields::Id.new(:path => [:id], :label => "Id") }
Expand Down
4 changes: 4 additions & 0 deletions test/unit/output/adapter/csv_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

let(:adapter) { HammerCLI::Output::Adapter::CSValues.new }

it "forbids default pagination" do
adapter.paginate_by_default?.must_equal false
end

context "print_collection" do

let(:field_name) { Fields::Field.new(:path => [:name], :label => "Name") }
Expand Down
4 changes: 4 additions & 0 deletions test/unit/output/adapter/json_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
let(:context) {{}}
let(:adapter) { HammerCLI::Output::Adapter::Json.new(context, HammerCLI::Output::Output.formatters) }

it "forbids default pagination" do
adapter.paginate_by_default?.must_equal false
end

context "print_message" do
it "prints the message" do
params = { :a => 'Test', :b => 83 }
Expand Down
4 changes: 4 additions & 0 deletions test/unit/output/adapter/table_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

let(:adapter) { HammerCLI::Output::Adapter::Table.new }

it "allows default pagination" do
adapter.paginate_by_default?.must_equal true
end

context "print_collection" do

let(:field_name) { Fields::Field.new(:path => [:fullname], :label => "Name") }
Expand Down
4 changes: 4 additions & 0 deletions test/unit/output/adapter/yaml_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
let(:context) {{}}
let(:adapter) { HammerCLI::Output::Adapter::Yaml.new(context, HammerCLI::Output::Output.formatters) }

it "forbids default pagination" do
adapter.paginate_by_default?.must_equal false
end

context "print_message" do
it "prints the message" do
params = { :a => 'Test', :b => 83 }
Expand Down

0 comments on commit 7904f9a

Please sign in to comment.