lib/nanoc/cli.rb in nanoc-3.4.3 vs lib/nanoc/cli.rb in nanoc-3.5.0b1
- old
+ new
@@ -51,10 +51,15 @@
self.setup
self.root_command.run(args)
end
end
+ # @return [Cri::Command] The root command, i.e. the commandline tool itself
+ def self.root_command
+ @root_command
+ end
+
# Adds the given command to the collection of available commands.
#
# @param [Cri::Command] cmd The command to add
#
# @return [void]
@@ -78,10 +83,14 @@
# @return [void]
def self.setup_commands
# Reinit
@root_command = nil
+ # Add root command
+ filename = File.dirname(__FILE__) + "/cli/commands/nanoc.rb"
+ @root_command = self.load_command_at(filename)
+
# Add help command
help_cmd = Cri::Command.new_basic_help
self.add_command(help_cmd)
# Add other commands
@@ -133,47 +142,43 @@
# Done
cmd
end
- # @return [Cri::Command] The root command, i.e. the commandline tool itself
- def self.root_command
- @root_command ||= begin
- filename = File.dirname(__FILE__) + "/cli/commands/nanoc.rb"
- self.load_command_at(filename)
- end
- end
-
# @return [Array] The directory contents
def self.recursive_contents_of(path)
return [] unless File.directory?(path)
files, dirs = *Dir[path + '/*'].sort.partition { |e| File.file?(e) }
dirs.each { |d| files.concat self.recursive_contents_of(d) }
files
end
- # Wraps `$stdout` and `$stderr` in appropriate cleaning streams.
+ # Wraps the given stream in a cleaning stream. The cleaning streams will
+ # have the proper stream cleaners configured.
#
- # @return [void]
- def self.setup_cleaning_streams
- $stdout = Nanoc::CLI::CleaningStream.new($stdout)
- $stderr = Nanoc::CLI::CleaningStream.new($stderr)
+ # @param [IO] io The stream to wrap
+ #
+ # @return [::Nanoc::CLI::CleaningStream]
+ def self.wrap_in_cleaning_stream(io)
+ cio = ::Nanoc::CLI::CleaningStream.new(io)
- if !self.enable_utf8?($stdout)
- $stdout.add_stream_cleaner(Nanoc::CLI::StreamCleaners::UTF8)
+ if !self.enable_utf8?(io)
+ cio.add_stream_cleaner(Nanoc::CLI::StreamCleaners::UTF8)
end
- if !self.enable_utf8?($stderr)
- $stderr.add_stream_cleaner(Nanoc::CLI::StreamCleaners::UTF8)
+ if !self.enable_ansi_colors?(io)
+ cio.add_stream_cleaner(Nanoc::CLI::StreamCleaners::ANSIColors)
end
- if !self.enable_ansi_colors?($stdout)
- $stdout.add_stream_cleaner(Nanoc::CLI::StreamCleaners::ANSIColors)
- end
+ cio
+ end
- if !self.enable_ansi_colors?($stderr)
- $stderr.add_stream_cleaner(Nanoc::CLI::StreamCleaners::ANSIColors)
- end
+ # Wraps `$stdout` and `$stderr` in appropriate cleaning streams.
+ #
+ # @return [void]
+ def self.setup_cleaning_streams
+ $stdout = self.wrap_in_cleaning_stream($stdout)
+ $stderr = self.wrap_in_cleaning_stream($stderr)
end
# @return [Boolean] true if UTF-8 support is present, false if not
def self.enable_utf8?(io)
return true if !io.tty?