Class: Nanoc2::CLI::Base
- Inherits:
-
Cri::Base
- Object
- Cri::Base
- Nanoc2::CLI::Base
- Defined in:
- lib/nanoc2/cli/base.rb
Overview
Nanoc2::CLI::Base is the central class representing a commandline nanoc tool. It has a list of commands, and is linked to a specific nanoc site.
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#site ⇒ Object
readonly
Gets the site (Nanoc2::Site) in the current directory and loads its data.
Instance Method Summary collapse
-
#global_option_definitions ⇒ Object
Returns the list of global option definitionss.
- #handle_option(option) ⇒ Object
-
#initialize ⇒ Base
constructor
Creates a new instance of the commandline nanoc tool.
-
#require_site ⇒ Object
Helper function which can be called when a command is executed that requires a site, such as the compile command.
-
#set_vcs(vcs_name) ⇒ Object
Sets the data source’s VCS to the VCS with the given name.
Constructor Details
#initialize ⇒ Base
Creates a new instance of the commandline nanoc tool.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/nanoc2/cli/base.rb', line 10 def initialize super('nanoc2') # Add help command self.help_command = Nanoc2::CLI::HelpCommand.new add_command(self.help_command) # Add other commands add_command(Nanoc2::CLI::AutocompileCommand.new) add_command(Nanoc2::CLI::CompileCommand.new) add_command(Nanoc2::CLI::CreateLayoutCommand.new) add_command(Nanoc2::CLI::CreatePageCommand.new) add_command(Nanoc2::CLI::CreateSiteCommand.new) add_command(Nanoc2::CLI::CreateTemplateCommand.new) add_command(Nanoc2::CLI::InfoCommand.new) add_command(Nanoc2::CLI::SwitchCommand.new) add_command(Nanoc2::CLI::UpdateCommand.new) end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
7 8 9 |
# File 'lib/nanoc2/cli/base.rb', line 7 def commands @commands end |
#site ⇒ Object (readonly)
Gets the site (Nanoc2::Site) in the current directory and loads its data.
40 41 42 |
# File 'lib/nanoc2/cli/base.rb', line 40 def site @site end |
Instance Method Details
#global_option_definitions ⇒ Object
Returns the list of global option definitionss.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/nanoc2/cli/base.rb', line 90 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 => 'verbose', :short => 'V', :argument => :forbidden, :desc => 'make nanoc output more detailed' }, { :long => 'version', :short => 'v', :argument => :forbidden, :desc => 'show version information and quit' } ] end |
#handle_option(option) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/nanoc2/cli/base.rb', line 111 def handle_option(option) # Handle no-color option if option == :'no-color' Nanoc2::CLI::Logger.instance.color = false # Handle verbose option elsif option == :verbose Nanoc2::CLI::Logger.instance.level = :low # Handle version option elsif option == :version puts "nanoc #{Nanoc2::VERSION} (c) 2007-2010 Denis Defreyne." puts "Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) running on #{RUBY_PLATFORM}" exit 0 # Handle help option elsif option == :help show_help exit 0 end end |
#require_site ⇒ Object
Helper function which can be called when a command is executed that requires a site, such as the compile command.
31 32 33 34 35 36 37 |
# File 'lib/nanoc2/cli/base.rb', line 31 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(vcs_name) ⇒ Object
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=).
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/nanoc2/cli/base.rb', line 73 def set_vcs(vcs_name) # Skip if not possible return if vcs_name.nil? return if site.nil? or !site.data_source.respond_to?(:vcs=) # Find VCS vcs_class = Nanoc2::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 # Set VCS site.data_source.vcs = vcs_class.new end |