Ruby gem, library, class to implement typical functionality of a utility like cp?

I’m in the process of writing a small utility in Ruby to convert files
in one
format to a different format.

Eventually it would be nice to to have the utility incorporate all or
most of
the command line functionality and options of a command like cp, mv, or
ln
(with suitable variations). For example, it would be nice to invoke it
in
any of 3 forms, like:

cp [OPTION]… SOURCE DEST
cp [OPTION]… SOURCE… DIRECTORY
cp [OPTION]… --target-directory=DIRECTORY SOURCE…

and to use many of the options available to cp like help, backup, force,
interactive, …

Is there a Ruby gem, library, class, or whatever that implements some or
all
of that functionality?

Randy K.

On Oct 14, 2007, at 1:43 PM, Randy K. wrote:

any of 3 forms, like:
some or all
of that functionality?

Randy K.

require ‘fileutils’

FileUtils.mv src, dst

etc…

cheers.

a @ http://codeforpeople.com/

On Sunday 14 October 2007 07:22 pm, ara.t.howard wrote:

invoke it in
Is there a Ruby gem, library, class, or whatever that implements
some or all
of that functionality?

Randy K.

require ‘fileutils’

FileUtils.mv src, dst

Ara,

Thanks! You’ve answered the question I asked, but not the question I
really
intended to ask ;-), although your answer may be helpful anyway.

What I’m really looking for is a gem, library, class, or even just
another
utility written in Ruby (that I could use as a template) that processes
command line parameters in a fashion like some typical *nix utilities
(like
maybe cp, ln, mv, …).

In other words, if I found such a utility written in Ruby, I’d think
about
leaving the “framework” that processes the command line parameters (like
–help (-h), --force (-f), --interactive (-i), --backup and stripping
out the
code that performs the function of that utility, substituting the
functionality I need. (And changing the actions for the various command
line
parameters as appropriate.)

The code is probably not that hard to write, I just thought that if
somebody
had already written it, I could save some time and effort (assuming
there
were no licensing or copyright issues).

Randy K.

On Monday 15 October 2007 10:12 am, mortee wrote:

You’re looking for optparse. I guess it’s not a gem but part of the
standard library.

Yes, wonderful, thanks!

And looking it up in the pickaxe(2) also leads me to GetoptLong so there
appear to be at least two options–now (or soon) I’ll have to spend a
little
time deciding which is most useful to me. (A nice problem to have :wink:

Randy K.

Randy K. wrote:

In other words, if I found such a utility written in Ruby, I’d think about
leaving the “framework” that processes the command line parameters (like
–help (-h), --force (-f), --interactive (-i), --backup and stripping out the
code that performs the function of that utility, substituting the
functionality I need. (And changing the actions for the various command line
parameters as appropriate.)

You’re looking for optparse. I guess it’s not a gem but part of the
standard library.

mortee

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs