module Detroit::ShellUtils
ShellUtils
provides the whole slew of FileUtils, FileTest
and File class methods in a single module and modifies methods according to noop? and verbose? options.
Constants
- RUBY
Current ruby binary.
Attributes
– Standard IO ———————————————————-
Public Instance Methods
# File lib/detroit/shell_utils.rb, line 226 def absolute?(path) ; FileTest.absolute?(path) ; end
Append to file.
# File lib/detroit/shell_utils.rb, line 259 def append(path, text) $stderr.puts "append #{path}" if trace? File.open(path, 'a'){ |f| f << text } unless noop? end
Convenient method to get simple console reply.
# File lib/detroit/shell_utils.rb, line 133 def ask(question) stdout.print "#{question} " stdout.flush input = stdin.gets #until inp = stdin.gets ; sleep 1 ; end input.strip end
– File Methods ———————————————————
# File lib/detroit/shell_utils.rb, line 239 def atime(*args) ; File.ctime(*args) ; end
# File lib/detroit/shell_utils.rb, line 214 def blockdev?(path) ; FileTest.blockdev?(path) ; end
# File lib/detroit/shell_utils.rb, line 207 def chardev?(path) ; FileTest.chardev?(path) ; end
# File lib/detroit/shell_utils.rb, line 240 def ctime(*args) ; File.ctime(*args) ; end
# File lib/detroit/shell_utils.rb, line 67 def debug? ; @debug ; end
# File lib/detroit/shell_utils.rb, line 204 def directory?(path) ; FileTest.directory?(path) ; end
# File lib/detroit/shell_utils.rb, line 71 def dryrun? ; verbose? && noop? ; end
# File lib/detroit/shell_utils.rb, line 221 def executable?(path) ; FileTest.executable?(path) ; end
# File lib/detroit/shell_utils.rb, line 229 def executable_real?(path) ; FileTest.executable_real?(path) ; end
# File lib/detroit/shell_utils.rb, line 208 def exist?(path) ; FileTest.exist?(path) ; end
# File lib/detroit/shell_utils.rb, line 209 def exists?(path) ; FileTest.exists?(path) ; end
# File lib/detroit/shell_utils.rb, line 212 def file?(path) ; FileTest.file?(path) ; end
# File lib/detroit/shell_utils.rb, line 61 def force? ; @force ; end
# File lib/detroit/shell_utils.rb, line 215 def grpowned?(path) ; FileTest.grpowned?(path) ; end
# File lib/detroit/shell_utils.rb, line 232 def identical?(path, other) FileTest.identical?(path, other) end
# File lib/detroit/shell_utils.rb, line 19 def initialize_extension_defaults @quiet = false @trial = false @noop = false @force = false super() if defined?(super) end
# File lib/detroit/shell_utils.rb, line 29 def initialize_extensions #extend(fileutils) super() if defined?(super) end
Fallback to filutils.
# File lib/detroit/shell_utils.rb, line 35 def method_missing(s, *a, &b) if fileutils.respond_to?(s) fileutils.send(s, *a, &b) else super(s, *a, &b) end end
# File lib/detroit/shell_utils.rb, line 241 def mtime(*args) ; File.mtime(*args) ; end
TODO: Ultimately merge glob and multiglob
.
# File lib/detroit/shell_utils.rb, line 191 def multiglob(*args, &blk) Dir.multiglob(*args, &blk) end
# File lib/detroit/shell_utils.rb, line 196 def multiglob_r(*args, &blk) Dir.multiglob_r(*args, &blk) end
# File lib/detroit/shell_utils.rb, line 70 def noop? ; @trial ; end
# File lib/detroit/shell_utils.rb, line 219 def owned?(path) ; FileTest.owned?(path) ; end
TODO: Until we have better support for getting input across platforms, we are using ask
for passwords too.
# File lib/detroit/shell_utils.rb, line 142 def password(prompt=nil) prompt ||= "Enter Password: " ask(prompt) end
A path is required for shell methods to operate. If no path is set than the current working path is used.
# File lib/detroit/shell_utils.rb, line 45 def path @path ||= Dir.pwd end
Set shell path.
# File lib/detroit/shell_utils.rb, line 50 def path=(dir) @path = dir end
# File lib/detroit/shell_utils.rb, line 211 def pipe?(path) ; FileTest.pipe?(path) ; end
# File lib/detroit/shell_utils.rb, line 12 def prerequisite require 'rbconfig' require 'ansi/core' #require 'detroit/core_ext/shell_extensions' end
# File lib/detroit/shell_utils.rb, line 94 def print(str=nil) return if silent? stdout.print(str.to_s) end
# File lib/detroit/shell_utils.rb, line 100 def puts(str=nil) return if silent? stdout.puts(str.to_s) end
# File lib/detroit/shell_utils.rb, line 63 def quiet? ; @quiet ; end
Read file.
# File lib/detroit/shell_utils.rb, line 248 def read(path) File.read(path) end
# File lib/detroit/shell_utils.rb, line 206 def readable?(path) ; FileTest.readable?(path) ; end
# File lib/detroit/shell_utils.rb, line 230 def readable_real?(path) ; FileTest.readable_real?(path) ; end
# File lib/detroit/shell_utils.rb, line 225 def relative?(path) ; FileTest.relative?(path) ; end
Same as status.
@deprecated
Doubley redundant with #status and #puts.
Shell-out to ruby.
# File lib/detroit/shell_utils.rb, line 184 def ruby(cmd) sh RUBY + " " + cmd end
# File lib/detroit/shell_utils.rb, line 223 def safe?(path) ; FileTest.safe?(path) ; end
# File lib/detroit/shell_utils.rb, line 216 def setgid?(path) ; FileTest.setgid?(path) ; end
# File lib/detroit/shell_utils.rb, line 217 def setuid?(path) ; FileTest.setuid?(path) ; end
Shell runner.
# File lib/detroit/shell_utils.rb, line 163 def sh(cmd) trace cmd return true if noop? success = nil if quiet? silently{ success = system(cmd) } else success = system(cmd) end success end
# File lib/detroit/shell_utils.rb, line 73 def silent? ; @quiet ; end
– File Testing ———————————————————
# File lib/detroit/shell_utils.rb, line 202 def size(path) ; FileTest.size(path) ; end
# File lib/detroit/shell_utils.rb, line 203 def size?(path) ; FileTest.size?(path) ; end
# File lib/detroit/shell_utils.rb, line 218 def socket?(path) ; FileTest.socket?(path) ; end
# File lib/detroit/shell_utils.rb, line 112 def status(message) return if silent? stdout.puts "#{message}".ansi(:bold) end
# File lib/detroit/shell_utils.rb, line 89 def stderr @stdout ||= $stderr end
# File lib/detroit/shell_utils.rb, line 85 def stdin @stdin ||= $stdin end
# File lib/detroit/shell_utils.rb, line 81 def stdout @stdout ||= $stdout end
# File lib/detroit/shell_utils.rb, line 213 def sticky?(path) ; FileTest.sticky?(path) ; end
# File lib/detroit/shell_utils.rb, line 205 def symlink?(path) ; FileTest.symlink?(path) ; end
Internal trace report. Only output if in trace mode.
# File lib/detroit/shell_utils.rb, line 124 def trace(message) return if silent? if trace? stdout.print "TRIAL RUN " if trial? stdout.puts message end end
# File lib/detroit/shell_utils.rb, line 66 def trace? ; @trace ; end
# File lib/detroit/shell_utils.rb, line 64 def trial? ; @trial ; end
# File lib/detroit/shell_utils.rb, line 243 def utime(*args) ; File.utime(*args) unless noop? ; end
# File lib/detroit/shell_utils.rb, line 69 def verbose? ; @verbose ; end
# File lib/detroit/shell_utils.rb, line 106 def warn(message) return if silent? stderr.puts "WARNING ".ansi(:yellow) + message.to_s end
# File lib/detroit/shell_utils.rb, line 220 def writable?(path) ; FileTest.writable?(path) ; end
# File lib/detroit/shell_utils.rb, line 228 def writable_real?(path) ; FileTest.writable_real?(path) ; end
Write file.
# File lib/detroit/shell_utils.rb, line 253 def write(path, text) $stderr.puts "write #{path}" if trace? File.open(path, 'w'){ |f| f << text } unless noop? end
# File lib/detroit/shell_utils.rb, line 210 def zero?(path) ; FileTest.zero?(path) ; end