Class: Nanoc::CLI::Commands::Prune Private

Inherits:
Nanoc::CLI::CommandRunner show all
Defined in:
lib/nanoc/cli/commands/prune.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Methods inherited from Nanoc::CLI::CommandRunner

#call, #debug?, enter_site_dir, find_site_dir, #in_site_dir?, #load_site

Instance Method Details

#runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/nanoc/cli/commands/prune.rb', line 20

def run
  @site = load_site
  res = Nanoc::Core::Compiler.new_for(@site).run_until_reps_built
  reps = res.fetch(:reps)

  listener_class = Nanoc::CLI::CompileListeners::FileActionPrinter
  listener = listener_class.new(reps:)
  listener.start_safely

  if options.key?(:yes)
    Nanoc::Core::Pruner.new(@site.config, reps, exclude: prune_config_exclude).run
  elsif options.key?(:'dry-run')
    Nanoc::Core::Pruner.new(@site.config, reps, exclude: prune_config_exclude, dry_run: true).run
  else
    $stderr.puts 'WARNING: Since the prune command is a destructive command, it requires an additional --yes flag in order to work.'
    $stderr.puts
    $stderr.puts 'Please ensure that the output directory does not contain any files (such as images or stylesheets) that are necessary but are not managed by Nanoc. If you want to get a list of all files that would be removed, pass --dry-run.'
    exit 1
  end
ensure
  listener&.stop_safely
end