From 24833587d378ea690b5d91c18a8b2f4c0754696d Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 13 Sep 2013 07:28:23 +0000 Subject: rbuninstall.rb: tty * tool/rbuninstall.rb: show progress if tty and add --tty option. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- tool/rbuninstall.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tool/rbuninstall.rb b/tool/rbuninstall.rb index d04800bac7..1a11766790 100755 --- a/tool/rbuninstall.rb +++ b/tool/rbuninstall.rb @@ -1,12 +1,15 @@ #! /usr/bin/ruby -nl BEGIN { $dryrun = false + $tty = STDOUT.tty? until ARGV.empty? case ARGV[0] when /\A--destdir=(.*)/ $destdir = $1 when /\A-n\z/ $dryrun = true + when /\A--(?:no-)?tty\z/ + $tty = !$1 else break end @@ -20,10 +23,10 @@ $_ = File.join($destdir, $_) if $destdir list << $_ END { status = true + $\ = ors = (!$dryrun and $tty) ? "\e[K\r" : "\n" $files.each do |file| - if $dryrun - puts "rm #{file}" - else + print "rm #{file}" + unless $dryrun begin File.unlink(file) rescue Errno::ENOENT @@ -38,9 +41,8 @@ END { unlink[dir] = true end while dir = $dirs.pop - if $dryrun - puts "rmdir #{dir}" - else + print "rmdir #{dir}" + unless $dryrun begin begin unlink.delete(dir) @@ -59,5 +61,7 @@ END { end end end + $\ = nil + print ors.chomp exit(status) } -- cgit v1.2.3