lib/nanoc/cli.rb in nanoc-3.7.5 vs lib/nanoc/cli.rb in nanoc-3.8.0

- old
+ new

@@ -45,23 +45,23 @@ # @since 3.2.0 def self.debug=(boolean) @debug = boolean end - # Invokes the nanoc commandline tool with the given arguments. + # Invokes the nanoc command-line tool with the given arguments. # - # @param [Array<String>] args An array of commandline arguments + # @param [Array<String>] args An array of command-line arguments # # @return [void] def self.run(args) Nanoc::CLI::ErrorHandler.handle_while do setup root_command.run(args) end end - # @return [Cri::Command] The root command, i.e. the commandline tool itself + # @return [Cri::Command] The root command, i.e. the command-line tool itself def self.root_command @root_command end # Adds the given command to the collection of available commands. @@ -81,11 +81,11 @@ add_after_setup_proc(block) end protected - # Makes the commandline interface ready for use. + # Makes the command-line interface ready for use. # # @return [void] def self.setup setup_cleaning_streams setup_commands @@ -115,19 +115,28 @@ cmd = load_command_at(cmd_filename) add_command(cmd) end end - # Loads site-specific commands in `commands/`. + # Loads site-specific commands. # # @return [void] def self.load_custom_commands - recursive_contents_of('commands').each do |filename| + if Nanoc::Site.cwd_is_nanoc_site? + site = Nanoc::Site.new('.') + site.config[:commands_dirs].each do |path| + load_commands_at(path) + end + end + end + + def self.load_commands_at(path) + recursive_contents_of(path).each do |filename| # Create command command = Nanoc::CLI.load_command_at(filename) # Get supercommand - pieces = filename.gsub(/^commands\/|\.rb$/, '').split('/') + pieces = filename.gsub(/^#{path}\/|\.rb$/, '').split('/') pieces = pieces[0, pieces.size - 1] || [] root = Nanoc::CLI.root_command supercommand = pieces.reduce(root) do |cmd, piece| cmd.nil? ? nil : cmd.command_named(piece) end