Skip to content

Commit

Permalink
feat: add --enqueue-remaining option to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosgz committed Nov 21, 2024
1 parent 1ed90f3 commit 7e4ca60
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/site_maps/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class CLI < Thor
method_option :config_file, type: :string, aliases: "-r", default: nil
method_option :max_threads, type: :numeric, aliases: "-c", default: 4
method_option :context, type: :hash, default: {}
method_option :enqueue_remaining, type: :boolean, default: false

desc "generate 1st_process,2nd_process ... ,Nth_process", "Generate sitemap.xml files for the given processes"
default_command :start
Expand All @@ -16,27 +17,30 @@ def generate(processes = "")
load_rails if rails_app?

opts = (@options || {}).transform_keys(&:to_sym)
if (logfile = opts.delete(:logfile))
if (logfile = opts[:logfile])
SiteMaps.logger = Logger.new(logfile)
end
if opts.delete(:debug)
if opts[:debug]
SiteMaps.logger.level = Logger::DEBUG
end

SiteMaps::Notification.subscribe(SiteMaps::Runner::EventListener)

runner = SiteMaps.generate(
config_file: opts.delete(:config_file),
max_threads: opts.delete(:max_threads)
config_file: opts[:config_file],
max_threads: opts[:max_threads]
)
if processes.empty?
runner.enqueue_all
else
kwargs = opts.delete(:context) { {} }.transform_keys(&:to_sym)
kwargs = (opts[:context] || {}).transform_keys(&:to_sym)
processes.split(",").each do |process|
runner.enqueue(process.strip.to_sym, **kwargs)
end
end
if opts[:enqueue_remaining]
runner.enqueue_remaining
end

runner.run
end
Expand Down

0 comments on commit 7e4ca60

Please sign in to comment.