Class: Nanoc3::CLI::Command
- Inherits:
-
Object
- Object
- Nanoc3::CLI::Command
- Defined in:
- lib/nanoc3/cli/command.rb
Overview
An abstract superclass for commands that can be executed. These are not the same as Cri commands, but are used in conjuction with Cri commands. nanoc commands will be called by Cri commands and will perform the actual execution of the command, as well as perform error handling if necessary.
Direct Known Subclasses
Nanoc3::CLI::Commands::AutoCompile, Nanoc3::CLI::Commands::Compile, Nanoc3::CLI::Commands::CreateItem, Nanoc3::CLI::Commands::CreateLayout, Nanoc3::CLI::Commands::CreateSite, Nanoc3::CLI::Commands::Debug, Nanoc3::CLI::Commands::Info, Nanoc3::CLI::Commands::Update, Nanoc3::CLI::Commands::View, Nanoc3::CLI::Commands::Watch
Instance Attribute Summary collapse
-
#arguments ⇒ Array
readonly
The list of arguments.
-
#command ⇒ Cri::Command
readonly
The Cri command.
-
#options ⇒ Hash
readonly
A hash contain the options and their values.
Class Method Summary collapse
-
.call(options, arguments, command) ⇒ void
Runs the command with the given options, arguments and Cri command.
Instance Method Summary collapse
-
#call ⇒ void
Runs the command.
-
#initialize(options, arguments, command) ⇒ Command
constructor
A new instance of Command.
-
#run ⇒ void
abstract
Performs the actual execution of the command.
-
#site ⇒ Nanoc3::Site
Gets the site (Site instance) in the current directory and loads its data.
Constructor Details
#initialize(options, arguments, command) ⇒ Command
Returns a new instance of Command.
25 26 27 28 29 |
# File 'lib/nanoc3/cli/command.rb', line 25 def initialize(, arguments, command) @options = @arguments = arguments @command = command end |
Instance Attribute Details
#arguments ⇒ Array (readonly)
Returns The list of arguments.
15 16 17 |
# File 'lib/nanoc3/cli/command.rb', line 15 def arguments @arguments end |
#command ⇒ Cri::Command (readonly)
Returns The Cri command.
18 19 20 |
# File 'lib/nanoc3/cli/command.rb', line 18 def command @command end |
#options ⇒ Hash (readonly)
Returns A hash contain the options and their values.
12 13 14 |
# File 'lib/nanoc3/cli/command.rb', line 12 def @options end |
Class Method Details
.call(options, arguments, command) ⇒ void
This method returns an undefined value.
Runs the command with the given options, arguments and Cri command. This is a convenience method so that no individual command needs to be created.
42 43 44 |
# File 'lib/nanoc3/cli/command.rb', line 42 def self.call(, arguments, command) self.new(, arguments, command).call end |
Instance Method Details
#call ⇒ void
This method returns an undefined value.
Runs the command.
49 50 51 52 53 |
# File 'lib/nanoc3/cli/command.rb', line 49 def call Nanoc3::CLI::ErrorHandler.handle_while(:command => self) do self.run end end |
#run ⇒ void
This method returns an undefined value.
Performs the actual execution of the command.
60 61 |
# File 'lib/nanoc3/cli/command.rb', line 60 def run end |
#site ⇒ Nanoc3::Site
Gets the site (Site instance) in the current directory and loads its data.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/nanoc3/cli/command.rb', line 67 def site # Load site if possible @site ||= nil if File.file?('config.yaml') && @site.nil? begin @site = Nanoc3::Site.new('.') rescue Nanoc3::Errors::UnknownDataSource => e $stderr.puts "Unknown data source: #{e}" exit 1 end end @site end |