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

**URL:** <https://www.ruby-forum.com/t/ruby-gem-library-class-to-implement-typical-functionality-of-a-utility-like-cp/117216>\
**Category:** Ruby\
**Created:** [October 14, 2007, 9:45pm UTC](https://www.ruby-forum.com/t/ruby-gem-library-class-to-implement-typical-functionality-of-a-utility-like-cp/117216 "2007-10-14T21:45:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![randy\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@randy\_k](https://www.ruby-forum.com/u/randy_k)\
**Post date:** [October 14, 2007, 9:45pm UTC](https://www.ruby-forum.com/t/ruby-gem-library-class-to-implement-typical-functionality-of-a-utility-like-cp/117216/1 "2007-10-14T21:45:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![randy\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@randy\_k](https://www.ruby-forum.com/u/randy_k)\
**Post date:** [October 15, 2007, 1:24am UTC](https://www.ruby-forum.com/t/ruby-gem-library-class-to-implement-typical-functionality-of-a-utility-like-cp/117216/2 "2007-10-15T01:24:57Z")

</div>

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/](http://codeforpeople.com/)

---

<div class="post-metadata">

**Author:** ![randy\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@randy\_k](https://www.ruby-forum.com/u/randy_k)\
**Post date:** [October 15, 2007, 1:17pm UTC](https://www.ruby-forum.com/t/ruby-gem-library-class-to-implement-typical-functionality-of-a-utility-like-cp/117216/3 "2007-10-15T13:17:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![randy\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@randy\_k](https://www.ruby-forum.com/u/randy_k)\
**Post date:** [October 15, 2007, 4:29pm UTC](https://www.ruby-forum.com/t/ruby-gem-library-class-to-implement-typical-functionality-of-a-utility-like-cp/117216/4 "2007-10-15T16:29:26Z")

</div>

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 😉

Randy K.

---

<div class="post-metadata">

**Author:** ![randy\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/258eb7/32.png) [@randy\_k](https://www.ruby-forum.com/u/randy_k)\
**Post date:** [October 15, 2007, 4:13pm UTC](https://www.ruby-forum.com/t/ruby-gem-library-class-to-implement-typical-functionality-of-a-utility-like-cp/117216/5 "2007-10-15T16:13:01Z")

</div>

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
