Class: Nanoc3::CLI::Base
- Cri::Base
- Nanoc3::CLI::Base
Constructor Summary
public
initialize
[View source]
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/nanoc3/cli/base.rb', line 7 def initialize super('nanoc3') # Add help command self.help_command = Nanoc3::CLI::Commands::Help.new add_command(self.help_command) # Add other commands add_command(Nanoc3::CLI::Commands::Autocompile.new) add_command(Nanoc3::CLI::Commands::Compile.new) add_command(Nanoc3::CLI::Commands::CreateLayout.new) add_command(Nanoc3::CLI::Commands::CreateItem.new) add_command(Nanoc3::CLI::Commands::CreateSite.new) add_command(Nanoc3::CLI::Commands::Info.new) add_command(Nanoc3::CLI::Commands::Update.new) end |
Public Visibility
Public Class Method Summary
| shared_base |
|---|
Public Instance Method Summary
| #global_option_definitions |
Returns the list of global option definitionss. |
|---|---|
| #handle_option(option) | |
| #require_site |
Helper function which can be called when a command is executed that requires a site, such as the compile command. |
| #set_vcs(vcs_name) |
Sets the data source’s VCS to the VCS with the given name. |
| #site |
Gets the site (Nanoc3::Site) in the current directory and loads its data. |
Public Class Method Details
shared_base
Public Instance Method Details
global_option_definitions
public
global_option_definitions
Returns the list of global option definitionss.
[View source]
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/nanoc3/cli/base.rb', line 100 def global_option_definitions [ { :long => 'help', :short => 'h', :argument => :forbidden, :desc => 'show this help message and quit' }, { :long => 'no-color', :short => 'C', :argument => :forbidden, :desc => 'disable color' }, { :long => 'version', :short => 'v', :argument => :forbidden, :desc => 'show version information and quit' }, { :long => 'verbose', :short => 'V', :argument => :forbidden, :desc => 'make nanoc output more detailed' }, { :long => 'debug', :short => 'd', :argument => :forbidden, :desc => 'enable debugging (set $DEBUG to true)' }, { :long => 'warn', :short => 'w', :argument => :forbidden, :desc => 'enable warnings' } ] end |
handle_option
public
handle_option(option)
[View source]
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/nanoc3/cli/base.rb', line 129 def handle_option(option) case option when :version puts "nanoc #{Nanoc3::VERSION} (c) 2007-2009 Denis Defreyne." puts "Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) running on #{RUBY_PLATFORM}" exit 0 when :verbose Nanoc3::CLI::Logger.instance.level = :low when :debug $DEBUG = true when :warn $-w = true when :'no-color' Nanoc3::CLI::Logger.instance.color = false when :help show_help exit 0 end end |
require_site
public
require_site
Helper function which can be called when a command is executed that requires a site, such as the compile command.
[View source]
30 31 32 33 34 35 36 |
# File 'lib/nanoc3/cli/base.rb', line 30 def require_site if site.nil? $stderr.puts 'The current working directory does not seem to be a ' + 'valid/complete nanoc site directory; aborting.' exit 1 end end |
set_vcs
public
set_vcs(vcs_name)
Sets the data source’s VCS to the VCS with the given name. Does nothing when the site’s data source does not support VCSes (i.e. does not implement #vcs=).
[View source]
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/nanoc3/cli/base.rb', line 79 def set_vcs(vcs_name) # Skip if not possible return if vcs_name.nil? || site.nil? # Find VCS vcs_class = Nanoc3::Extra::VCS.named(vcs_name.to_sym) if vcs_class.nil? $stderr.puts "A VCS named #{vcs_name} was not found; aborting." exit 1 end site.data_sources.each do |data_source| # Skip if not possible next if !data_source.respond_to?(:vcs=) # Set VCS data_source.vcs = vcs_class.new end end |
site
public
site
Gets the site (Nanoc3::Site) in the current directory and loads its data.
[View source]
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/nanoc3/cli/base.rb', line 39 def site # Load site if possible if File.file?('config.yaml') && (!self.instance_variable_defined?(:@site) || @site.nil?) begin @site = Nanoc3::Site.new('.') rescue Nanoc3::Errors::UnknownDataSource => e $stderr.puts "Unknown data source: #{e}" exit 1 rescue StandardError, ScriptError => error # Header $stderr.puts '+--- /!\ ERROR /!\ -------------------------------------------+' $stderr.puts '| An exception occured while loading the site. If you think |' $stderr.puts '| this is a bug in nanoc, please do report it at |' $stderr.puts '| <http://projects.stoneship.org/trac/nanoc/newticket> -- |' $stderr.puts '| thanks in advance! |' $stderr.puts '+-------------------------------------------------------------+' # Exception $stderr.puts $stderr.puts '=== MESSAGE:' $stderr.puts $stderr.puts "#{error.class}: #{error.message}" # Backtrace require 'enumerator' $stderr.puts $stderr.puts '=== BACKTRACE:' $stderr.puts $stderr.puts error.backtrace.to_enum(:each_with_index).map { |item, index| " #{index}. #{item}" }.join("\n") exit 1 end end @site end |