Skip to content

Commit

Permalink
* lib/un.h (help): new. % ruby -run -e help cp
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4301 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
eban committed Aug 3, 2003
1 parent 6c52649 commit d665322
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ Sun Aug 3 18:03:44 2003 WATANABE Hirofumi <[email protected]>

* regex.h (re_mbctab): should refer to RUBY_EXPORT. [ruby-ext:02199]

* lib/un.h (help): new. % ruby -run -e help cp

Sun Aug 3 02:45:06 2003 Koji Arai <[email protected]>

* numeric.c (flo_to_s): get rid of buffer overflow.
Expand Down
57 changes: 44 additions & 13 deletions lib/un.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# ruby -run -e install -- [OPTION] SOURCE DEST
# ruby -run -e chmod -- [OPTION] OCTAL-MODE FILE
# ruby -run -e touch -- [OPTION] FILE
# ruby -run -e help [COMMAND]

require 'fileutils'
require 'getopts'
Expand Down Expand Up @@ -50,7 +51,7 @@ def setup(options = "")
yield ARGV, options, $OPT
end

#
##
# Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY
#
# ruby -run -e cp -- [OPTION] SOURCE DEST
Expand All @@ -59,6 +60,7 @@ def setup(options = "")
# -r copy recursively
# -v verbose
#

def cp
setup("pr") do |argv, options, opt|
cmd = "cp"
Expand All @@ -69,7 +71,7 @@ def cp
end
end

#
##
# Create a link to the specified TARGET with LINK_NAME.
#
# ruby -run -e ln -- [OPTION] TARGET LINK_NAME
Expand All @@ -78,6 +80,7 @@ def cp
# -f remove existing destination files
# -v verbose
#

def ln
setup("sf") do |argv, options, opt|
cmd = "ln"
Expand All @@ -88,13 +91,14 @@ def ln
end
end

#
##
# Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
#
# ruby -run -e mv SOURCE DEST
# ruby -run -e mv -- [OPTION] SOURCE DEST
#
# -v verbose
#

def mv
setup do |argv, options|
dest = argv.pop
Expand All @@ -103,7 +107,7 @@ def mv
end
end

#
##
# Remove the FILE
#
# ruby -run -e rm -- [OPTION] FILE
Expand All @@ -112,6 +116,7 @@ def mv
# -r remove the contents of directories recursively
# -v verbose
#

def rm
setup("fr") do |argv, options, opt|
cmd = "rm"
Expand All @@ -120,14 +125,15 @@ def rm
end
end

#
##
# Create the DIR, if they do not already exist.
#
# ruby -run -e mkdir -- [OPTION] DIR
#
# -p no error if existing, make parent directories as needed
# -v verbose
#

def mkdir
setup("p") do |argv, options, opt|
cmd = "mkdir"
Expand All @@ -136,20 +142,21 @@ def mkdir
end
end

#
##
# Remove the DIR.
#
# ruby -run -e rmdir DIR
# ruby -run -e rmdir -- [OPTION] DIR
#
# -v verbose
#

def rmdir
setup do |argv, options|
FileUtils.rmdir argv, options
end
end

#
##
# Copy SOURCE to DEST.
#
# ruby -run -e install -- [OPTION] SOURCE DEST
Expand All @@ -159,6 +166,7 @@ def rmdir
# -m set permission mode (as in chmod), instead of 0755
# -v verbose
#

def install
setup("pm:") do |argv, options, opt|
options[:mode] = opt["m"] ? opt["m"].oct : 0755
Expand All @@ -168,29 +176,52 @@ def install
end
end

#
##
# Change the mode of each FILE to OCTAL-MODE.
#
# ruby -run -e chmod OCTAL-MODE FILE
# ruby -run -e chmod -- [OPTION] OCTAL-MODE FILE
#
# -v verbose
#

def chmod
setup do |argv, options|
mode = argv.shift.oct
FileUtils.chmod mode, argv, options
end
end

#
##
# Update the access and modification times of each FILE to the current time.
#
# ruby -run -e touch FILE
# ruby -run -e touch -- [OPTION] FILE
#
# -v verbose
#

def touch
setup do |argv, options|
FileUtils.touch argv, options
end
end

##
# Display help message.
#
# ruby -run -e help [COMMAND]
#

def help
setup do |argv,|
all = argv.empty?
open(__FILE__) do |me|
while me.gets("##\n")
if help = me.gets("\n\n")
if all or argv.delete help[/-e \w+/].sub(/-e /, "")
print help.gsub(/^# ?/, "")
end
end
end
end
end
end

0 comments on commit d665322

Please sign in to comment.