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

R

Randy Kramer

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 Kramer
 
A

ara.t.howard

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 Kramer

require 'fileutils'

FileUtils.mv src, dst


etc...

cheers.

a @ http://codeforpeople.com/
 
R

Randy Kramer

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 Kramer

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 Kramer
 
M

mortee

Randy said:
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
 
R

Randy Kramer

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 ;-)

Randy Kramer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top