Sha256: 03c0f060d7c87be6b48f42cf2bdbc576ef76921b10cd859476a48b97eaec0b65

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 KB

Contents

QUIET = 0
NORMAL = 1
VERBOSE = 2

class Sys

  module Client
    def sys
      Sys.instance
    end

    #todo: look up ruby dynamic proxy
    def say(msg)
      sys.say(msg)
    end

    def svn(cmd, return_output = false)
      sys.svn(cmd, return_output)
    end

    def run(cmd, return_output = false)
      sys.run(cmd, return_output)
    end

    def verbosity=(level)
      sys.verbosity = level
    end

    def verbosity
      sys.verbosity
    end
  end

  @@instance = Sys.new

  def self.instance
    @@instance
  end

  attr_accessor :verbosity

  def initialize(verbosity = NORMAL)
    @verbosity = verbosity
  end

  def say(msg)
    puts msg if verbosity > QUIET
  end

  def svn(cmd, return_output = false)
    svncmd = "svn"
    svncmd += " --quiet" if (cmd =~ /^(up|co)/ && verbosity == QUIET)
    output = run("#{svncmd} #{cmd}", return_output)
    puts output if output && verbosity == VERBOSE
    output
  end

  def run(cmd, return_output = false)
    val = nil
    say("\t#{cmd}") if verbosity == VERBOSE
    if (return_output)
      val = `#{cmd}`
    else
      cmd += ">/dev/null"if verbosity == QUIET
      system(cmd)
    end
    unless $?.success?
      puts caller.join("\n\t")
      raise "Failure: '#{cmd}' returned #{$?.exitstatus}"
    end
    val
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sub-0.4.1 lib/sub/sys.rb
sub-0.4.2 lib/sub/sys.rb
sub-0.4.0 lib/sub/sys.rb