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

debug[W]
force[W]
quiet[W]
stderr[W]
stdin[W]
stdout[W]

– Standard IO ———————————————————-

trace[W]
trial[W]
verbose[W]

Public Instance Methods

absolute?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 226
def absolute?(path)        ; FileTest.absolute?(path)        ; end
append(path, text) click to toggle source

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
ask(question) click to toggle source

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
atime(*args) click to toggle source

– File Methods ———————————————————

# File lib/detroit/shell_utils.rb, line 239
def atime(*args) ; File.ctime(*args) ; end
blockdev?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 214
def blockdev?(path)        ; FileTest.blockdev?(path)        ; end
chardev?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 207
def chardev?(path)         ; FileTest.chardev?(path)         ; end
compare_file(path, other)
Alias for: identical?
ctime(*args) click to toggle source
# File lib/detroit/shell_utils.rb, line 240
def ctime(*args) ; File.ctime(*args) ; end
debug?() click to toggle source
# File lib/detroit/shell_utils.rb, line 67
def debug?   ; @debug   ; end
directory?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 204
def directory?(path)       ; FileTest.directory?(path)       ; end
dryrun?() click to toggle source
# File lib/detroit/shell_utils.rb, line 71
def dryrun?  ; verbose? && noop? ; end
executable?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 221
def executable?(path)      ; FileTest.executable?(path)      ; end
executable_real?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 229
def executable_real?(path) ; FileTest.executable_real?(path) ; end
exist?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 208
def exist?(path)           ; FileTest.exist?(path)           ; end
exists?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 209
def exists?(path)          ; FileTest.exists?(path)          ; end
file?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 212
def file?(path)            ; FileTest.file?(path)            ; end
force?() click to toggle source
# File lib/detroit/shell_utils.rb, line 61
def force?   ; @force   ; end
grpowned?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 215
def grpowned?(path)        ; FileTest.grpowned?(path)        ; end
identical?(path, other) click to toggle source
# File lib/detroit/shell_utils.rb, line 232
def identical?(path, other)
  FileTest.identical?(path, other)
end
Also aliased as: compare_file
initialize_extension_defaults() click to toggle source
Calls superclass method
# 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
initialize_extensions() click to toggle source
Calls superclass method
# File lib/detroit/shell_utils.rb, line 29
def initialize_extensions
  #extend(fileutils)
  super() if defined?(super)
end
method_missing(s, *a, &b) click to toggle source

Fallback to filutils.

Calls superclass method
# 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
mtime(*args) click to toggle source
# File lib/detroit/shell_utils.rb, line 241
def mtime(*args) ; File.mtime(*args) ; end
multiglob(*args, &blk) click to toggle source

TODO: Ultimately merge glob and multiglob.

# File lib/detroit/shell_utils.rb, line 191
def multiglob(*args, &blk)
  Dir.multiglob(*args, &blk)
end
multiglob_r(*args, &blk) click to toggle source
# File lib/detroit/shell_utils.rb, line 196
def multiglob_r(*args, &blk)
  Dir.multiglob_r(*args, &blk)
end
noop?() click to toggle source
# File lib/detroit/shell_utils.rb, line 70
def noop?    ; @trial   ; end
owned?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 219
def owned?(path)           ; FileTest.owned?(path)           ; end
password(prompt=nil) click to toggle source

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
path() click to toggle source

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
path=(dir) click to toggle source

Set shell path.

# File lib/detroit/shell_utils.rb, line 50
def path=(dir)
  @path = dir
end
pipe?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 211
def pipe?(path)            ; FileTest.pipe?(path)            ; end
prerequisite() click to toggle source
# File lib/detroit/shell_utils.rb, line 12
def prerequisite
  require 'rbconfig'
  require 'ansi/core'
  #require 'detroit/core_ext/shell_extensions'
end
print(str=nil) click to toggle source
puts(str=nil) click to toggle source
# File lib/detroit/shell_utils.rb, line 100
def puts(str=nil)
  return if silent?
  stdout.puts(str.to_s)
end
quiet?() click to toggle source
# File lib/detroit/shell_utils.rb, line 63
def quiet?   ; @quiet   ; end
read(path) click to toggle source

Read file.

# File lib/detroit/shell_utils.rb, line 248
def read(path)
  File.read(path)
end
readable?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 206
def readable?(path)        ; FileTest.readable?(path)        ; end
readable_real?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 230
def readable_real?(path)   ; FileTest.readable_real?(path)   ; end
relative?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 225
def relative?(path)        ; FileTest.relative?(path)        ; end
report(message)

Same as status.

@deprecated

Doubley redundant with #status and #puts.
Alias for: status
ruby(cmd) click to toggle source

Shell-out to ruby.

# File lib/detroit/shell_utils.rb, line 184
def ruby(cmd)
  sh RUBY + " " + cmd
end
safe?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 223
def safe?(path)            ; FileTest.safe?(path)            ; end
setgid?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 216
def setgid?(path)          ; FileTest.setgid?(path)          ; end
setuid?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 217
def setuid?(path)          ; FileTest.setuid?(path)          ; end
sh(cmd) click to toggle source

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
silent?() click to toggle source
# File lib/detroit/shell_utils.rb, line 73
def silent?  ; @quiet   ; end
size(path) click to toggle source

– File Testing ———————————————————

# File lib/detroit/shell_utils.rb, line 202
def size(path)             ; FileTest.size(path)             ; end
size?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 203
def size?(path)            ; FileTest.size?(path)            ; end
socket?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 218
def socket?(path)          ; FileTest.socket?(path)          ; end
status(message) click to toggle source
# File lib/detroit/shell_utils.rb, line 112
def status(message)
  return if silent?
  stdout.puts "#{message}".ansi(:bold)
end
Also aliased as: report
stderr() click to toggle source
# File lib/detroit/shell_utils.rb, line 89
def stderr
  @stdout ||= $stderr
end
stdin() click to toggle source
# File lib/detroit/shell_utils.rb, line 85
def stdin
  @stdin ||= $stdin
end
stdout() click to toggle source
# File lib/detroit/shell_utils.rb, line 81
def stdout
  @stdout ||= $stdout
end
sticky?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 213
def sticky?(path)          ; FileTest.sticky?(path)          ; end
trace(message) click to toggle source

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
trace?() click to toggle source
# File lib/detroit/shell_utils.rb, line 66
def trace?   ; @trace   ; end
trial?() click to toggle source
# File lib/detroit/shell_utils.rb, line 64
def trial?   ; @trial   ; end
utime(*args) click to toggle source
# File lib/detroit/shell_utils.rb, line 243
def utime(*args) ; File.utime(*args) unless noop? ; end
verbose?() click to toggle source
# File lib/detroit/shell_utils.rb, line 69
def verbose? ; @verbose ; end
warn(message) click to toggle source
# File lib/detroit/shell_utils.rb, line 106
def warn(message)
  return if silent?
  stderr.puts "WARNING ".ansi(:yellow) + message.to_s
end
writable?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 220
def writable?(path)        ; FileTest.writable?(path)        ; end
writable_real?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 228
def writable_real?(path)   ; FileTest.writable_real?(path)   ; end
write(path, text) click to toggle source

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
zero?(path) click to toggle source
# File lib/detroit/shell_utils.rb, line 210
def zero?(path)            ; FileTest.zero?(path)            ; end