diff --git a/lib/esse/cli/index.rb b/lib/esse/cli/index.rb index e9b0283..e773249 100644 --- a/lib/esse/cli/index.rb +++ b/lib/esse/cli/index.rb @@ -88,9 +88,20 @@ def open(*index_classes) option :suffix, type: :string, default: nil, aliases: '-s', desc: 'Suffix to append to index name' option :context, type: :hash, default: {}, required: true, desc: 'List of options to pass to the index class' option :repo, type: :string, default: nil, alias: '-r', desc: 'Repository to use for import' + option :eager_include_document_attributes, type: :string, default: nil, desc: 'Comma separated list of lazy document attributes to include to the bulk index request' + option :lazy_update_document_attributes, type: :string, default: nil, desc: 'Comma separated list of lazy document attributes to bulk update after the bulk index request' def import(*index_classes) require_relative 'index/import' - Import.new(indices: index_classes, **HashUtils.deep_transform_keys(options.to_h, &:to_sym)).run + opts = HashUtils.deep_transform_keys(options.to_h, &:to_sym) + opts.delete(:lazy_update_document_attributes) if opts[:lazy_update_document_attributes] == 'false' + opts.delete(:eager_include_document_attributes) if opts[:eager_include_document_attributes] == 'false' + if (val = opts[:eager_include_document_attributes]) + opts[:eager_include_document_attributes] = (val == 'true') ? true : val.split(',') + end + if (val = opts[:lazy_update_document_attributes]) + opts[:lazy_update_document_attributes] = (val == 'true') ? true : val.split(',') + end + Import.new(indices: index_classes, **opts).run end end end diff --git a/spec/esse/cli/index/import_spec.rb b/spec/esse/cli/index/import_spec.rb index 205afb3..6db585f 100644 --- a/spec/esse/cli/index/import_spec.rb +++ b/spec/esse/cli/index/import_spec.rb @@ -57,6 +57,46 @@ expect(CitiesIndex).to receive(:import).and_return(true) cli_exec(%w[index import CountiesIndex CitiesIndex]) end + + it 'allows --eager-include-document-attributes as a comma separated list' do + expect(CountiesIndex).to receive(:import).with(eager_include_document_attributes: %w[foo bar], context: {}).and_return(true) + cli_exec(%w[index import CountiesIndex --eager-include-document-attributes=foo,bar]) + end + + it 'allows --lazy-update-document-attributes as a single value' do + expect(CountiesIndex).to receive(:import).with(lazy_update_document_attributes: %w[foo], context: {}).and_return(true) + cli_exec(%w[index import CountiesIndex --lazy-update-document-attributes=foo]) + end + + it 'allows --lazy-update-document-attributes as true' do + expect(CountiesIndex).to receive(:import).with(lazy_update_document_attributes: true, context: {}).and_return(true) + cli_exec(%w[index import CountiesIndex --lazy-update-document-attributes=true]) + end + + it 'allows --lazy-update-document-attributes as false' do + expect(CountiesIndex).to receive(:import).with(context: {}).and_return(true) + cli_exec(%w[index import CountiesIndex --lazy-update-document-attributes=false]) + end + + it 'allows --lazy-update-document-attributes as a comma separated list' do + expect(CountiesIndex).to receive(:import).with(lazy_update_document_attributes: %w[foo bar], context: {}).and_return(true) + cli_exec(%w[index import CountiesIndex --lazy-update-document-attributes=foo,bar]) + end + + it 'allows --lazy-update-document-attributes as a single value' do + expect(CountiesIndex).to receive(:import).with(lazy_update_document_attributes: %w[foo], context: {}).and_return(true) + cli_exec(%w[index import CountiesIndex --lazy-update-document-attributes=foo]) + end + + it 'allows --lazy-update-document-attributes as true' do + expect(CountiesIndex).to receive(:import).with(lazy_update_document_attributes: true, context: {}).and_return(true) + cli_exec(%w[index import CountiesIndex --lazy-update-document-attributes=true]) + end + + it 'allows --lazy-update-document-attributes as false' do + expect(CountiesIndex).to receive(:import).with(context: {}).and_return(true) + cli_exec(%w[index import CountiesIndex --lazy-update-document-attributes=false]) + end end end end