Class: Nanoc::CLI::CommandRunner

Inherits:
Cri::CommandRunner
  • Object
show all
Defined in:
lib/nanoc/cli/command_runner.rb

Overview

A command runner subclass for nanoc commands that adds nanoc-specific convenience methods and error handling.

Direct Known Subclasses

Nanoc::CLI::Commands::AutoCompile, Nanoc::CLI::Commands::Check, Nanoc::CLI::Commands::Compile, Nanoc::CLI::Commands::CreateItem, Nanoc::CLI::Commands::CreateLayout, Nanoc::CLI::Commands::CreateSite, Nanoc::CLI::Commands::Deploy, Nanoc::CLI::Commands::Prune, Nanoc::CLI::Commands::Shell, Nanoc::CLI::Commands::ShowData, Nanoc::CLI::Commands::ShowPlugins, Nanoc::CLI::Commands::ShowRules, Nanoc::CLI::Commands::Sync, Nanoc::CLI::Commands::Update, Nanoc::CLI::Commands::ValidateCSS, Nanoc::CLI::Commands::ValidateHTML, Nanoc::CLI::Commands::ValidateLinks, Nanoc::CLI::Commands::View, Nanoc::CLI::Commands::Watch

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) call(opts, args, cmd)

Deprecated.

use Cri::CommandDSL#runner



35
36
37
# File 'lib/nanoc/cli/command_runner.rb', line 35

def self.call(opts, args, cmd)
  new(opts, args, cmd).call
end

Instance Method Details

- (void) call

This method returns an undefined value.



12
13
14
15
16
# File 'lib/nanoc/cli/command_runner.rb', line 12

def call
  Nanoc::CLI::ErrorHandler.handle_while(:command => self) do
    run
  end
end

- (Boolean) debug?

Returns true if debug output is enabled, false if not

Returns:

  • (Boolean)

    true if debug output is enabled, false if not

See Also:



70
71
72
# File 'lib/nanoc/cli/command_runner.rb', line 70

def debug?
  Nanoc::CLI.debug?
end

- (Boolean) is_in_site_dir?

Returns true if the current working directory is a nanoc site directory, false otherwise

Returns:

  • (Boolean)

    true if the current working directory is a nanoc site directory, false otherwise



41
42
43
# File 'lib/nanoc/cli/command_runner.rb', line 41

def is_in_site_dir?
  Nanoc::Site.cwd_is_nanoc_site?
end

- (void) load_site

This method returns an undefined value.

Asserts that the current working directory contains a site (just like #require_site) and loads the site into memory.



60
61
62
63
64
65
# File 'lib/nanoc/cli/command_runner.rb', line 60

def load_site
  require_site
  print 'Loading site data… '
  site.load
  puts 'done'
end

- (void) require_site

This method returns an undefined value.

Asserts that the current working directory contains a site (Site instance). If no site is present, prints an error message and exits.



50
51
52
53
54
# File 'lib/nanoc/cli/command_runner.rb', line 50

def require_site
  if site.nil?
    raise ::Nanoc::Errors::GenericTrivial, 'The current working directory does not seem to be a nanoc site.'
  end
end

- (Nanoc::Site) site

Gets the site (Site instance) in the current directory and loads its data.

Returns:

  • (Nanoc::Site)

    The site in the current working directory



22
23
24
25
26
27
28
29
30
# File 'lib/nanoc/cli/command_runner.rb', line 22

def site
  # Load site if possible
  @site ||= nil
  if self.is_in_site_dir? && @site.nil?
    @site = Nanoc::Site.new('.')
  end

  @site
end