feat(verbose): Add --verbose flag

This commit is contained in:
Pixelastic 2015-07-21 19:19:15 +02:00
parent 7b491e23af
commit f2d57d6902
3 changed files with 11 additions and 4 deletions

View File

@ -20,12 +20,13 @@ class AlgoliaSearchJekyll < Jekyll::Command
add_build_options(subcommand)
subcommand.action do |args, options|
@config = configuration_from_options(options)
default_options = {
'dry_run' => false
'dry_run' => false,
'verbose' => false
}
options = default_options.merge(options)
@config = configuration_from_options(options)
AlgoliaSearchJekyllPush.init_options(args, options, @config)
.jekyll_new(@config)
.process
@ -47,6 +48,8 @@ class AlgoliaSearchJekyll < Jekyll::Command
'Index posts that were marked as unpublished'
command.option 'dry_run', '--dry-run', '-n',
'Do a dry run, do not push records'
command.option 'verbose', '--verbose',
'Display more information on what is indexed'
end
end
end

View File

@ -20,6 +20,7 @@ class AlgoliaSearchJekyllPush < Jekyll::Command
@args = args
@options = options
@config = config
@is_verbose = @config['verbose']
# Allow for passing index name on the command line
index_name = args[0]
@ -57,8 +58,10 @@ class AlgoliaSearchJekyllPush < Jekyll::Command
# on disk
def site.write
items = []
is_verbose = config['verbose']
each_site_file do |file|
next unless AlgoliaSearchJekyllPush.indexable?(file)
Jekyll.logger.info "Extracting data from #{file.path}" if is_verbose
new_items = AlgoliaSearchRecordExtractor.new(file).extract
next if new_items.nil?
@ -107,7 +110,7 @@ class AlgoliaSearchJekyllPush < Jekyll::Command
def push(items)
AlgoliaSearchCredentialChecker.new(@config).assert_valid
is_dry_run = @options['dry_run']
is_dry_run = @config['dry_run']
Jekyll.logger.info '=== DRY RUN ===' if is_dry_run
# Create a temporary index

View File

@ -6,6 +6,7 @@ require 'json'
class AlgoliaSearchRecordExtractor
def initialize(file)
@file = file
@config = file.site.config
default_config = {
'record_css_selector' => 'p'
}