Class: Trop::Sh
- Inherits:
-
Object
- Object
- Trop::Sh
- Defined in:
- lib/trop/shell_deb_verb.rb
Constant Summary collapse
- DEFAULT =
false- @@verbose =
false- @@debug =
false
Class Method Summary collapse
- .cwd(*cmds) ⇒ Object
- .debug!(mode = true) ⇒ Object
- .debug? ⇒ Boolean
- .sh(*cmds) ⇒ Object
- .silence_streams(*streams) ⇒ Object
- .silent! ⇒ Object
- .silent? ⇒ Boolean
- .systemlocal(cmds) ⇒ Object
- .verbose! ⇒ Object
- .verbose? ⇒ Boolean
Class Method Details
.cwd(*cmds) ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/trop/shell_deb_verb.rb', line 102 def self.cwd(*cmds) wd = Pathname.new(RAKE_RUN_DIR).join('output') Dir.chdir(wd) do ret, out = systemlocal(cmds) return [ret, out] end end |
.debug!(mode = true) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/trop/shell_deb_verb.rb', line 65 def self.debug!(mode = true) if mode.false? @@debug = false ENV['DEBUG'] = nil else @@debug = true end return @@debug end |
.debug? ⇒ Boolean
59 60 61 62 63 |
# File 'lib/trop/shell_deb_verb.rb', line 59 def self.debug? @@debug = true unless ENV['DEBUG'].nil? @@debug = true if $DEBUG return @@debug end |
.sh(*cmds) ⇒ Object
110 111 112 113 |
# File 'lib/trop/shell_deb_verb.rb', line 110 def self.sh(*cmds) ret, out = systemlocal(cmds) return [ret, out] end |
.silence_streams(*streams) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/trop/shell_deb_verb.rb', line 33 def self.silence_streams(*streams) @@on_hold = streams.collect {|stream| stream.dup} streams.each do |stream| stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null') stream.sync = true end yield ensure streams.each_with_index do |stream, i| stream.reopen(@@on_hold[i]) end end |
.silent! ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/trop/shell_deb_verb.rb', line 47 def self.silent! @@verbose = false @@debug = false ENV['VERBOSE'] = nil ENV['DEBUG'] = nil return !!@@verbose && !!@@debug end |
.silent? ⇒ Boolean
55 56 57 |
# File 'lib/trop/shell_deb_verb.rb', line 55 def self.silent? return !(::Trop::Sh.verbose? || ::Trop::Sh.debug?) end |
.systemlocal(cmds) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/trop/shell_deb_verb.rb', line 76 def self.systemlocal(cmds) cmd = '' return [-1, ''] if cmds.nil? || cmds.blank? if cmds.is_a? Array cmds.each {|s| cmd = cmd + s.to_s + ' ' unless s.blank?} else cmd = cmds.to_s end puts "commands: #{cmd} " if Trop::Sh::debug? return [-1, ''] if cmd.blank? puts " #{cmd} ".colorize(:green) if Trop::Sh::verbose? # execute system call with return in stdout stdout = `#{cmd}` # silent if successful or not verbose if $CHILD_STATUS.success? puts stdout.to_s.colorize(:green) if Trop::Sh::verbose? return [0, stdout] end # error case puts " #{cmd} ".colorize(:red) puts " #{stdout}".colorize(:red) [-1, stdout] end |
.verbose! ⇒ Object
27 28 29 30 31 |
# File 'lib/trop/shell_deb_verb.rb', line 27 def self.verbose! @@verbose = true ENV['VERBOSE'] = "true" return !!@@verbose end |
.verbose? ⇒ Boolean
20 21 22 23 24 25 |
# File 'lib/trop/shell_deb_verb.rb', line 20 def self.verbose? if Rake::FileUtilsExt.verbose_flag == true || (!ENV['VERBOSE'].nil? && ENV['VERBOSE'] == 'true') || !(ENV['DEBUG'].nil?) @@verbose = true end return !!@@verbose end |