Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
usage 0.0.4 - The IO edition
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Steve Tuckner  
View profile  
 More options Oct 18 2005, 4:11 pm
Newsgroups: comp.lang.ruby
From: Steve Tuckner <stevetuck...@usfamily.net>
Date: Wed, 19 Oct 2005 05:11:03 +0900
Local: Tues, Oct 18 2005 4:11 pm
Subject: usage 0.0.4 - The IO edition
What is usage?
===========

Usage is simple way to access command line parameters for quick scripts
that you write where you don't want to even think about command line
processing. You just need to type in what would be the Unix synopsis for
the command and the usage does the rest.

What is new in this version (0.0.4)?
========================

This version now takes argument typing to a new level. Argument types
can be defined through a new plug-in architecture. Also with this
version, there are new argument types to handle common io operations
such as reading/writing files and reading http:// and ftp:// URI's
(thanks to open-uri). The gem and require name are now in lowercase!

Give me an example?
==============

Here is the world's shortest type checked URI (or file) to file copy
script. This will check if you want to over-write an existing file
(because of the >? instead of just >) and will give errors if the the
URI does not exist. It automatically converts www. and ftp. to
http://www. and ftp://ftp. respectively. The first argument can also
just be a filename.

uricopy.rb
----------
#!/usr/bin/env ruby
require "usage"

Usage.new "<@infile >?outfile" do |u|
    u.outfile.write(u.infile.read)
end

run it by entering:

uricopy.rb www.yahoo.com out.txt

How can I get it?
============

gem install usage

Where is it at?
=============

http://raa.ruby-lang.org/project/usage/
http://rubyforge.org/projects/usage

Thanks,

Steve Tuckner


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adam Sanderson  
View profile  
 More options Oct 19 2005, 12:39 pm
Newsgroups: comp.lang.ruby
From: "Adam Sanderson" <netgh...@gmail.com>
Date: 19 Oct 2005 09:39:48 -0700
Local: Wed, Oct 19 2005 12:39 pm
Subject: Re: usage 0.0.4 - The IO edition
This looks really handy, could you post a few more examples?
  .adam

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
stevetuckner  
View profile  
 More options Oct 19 2005, 2:08 pm
Newsgroups: comp.lang.ruby
From: stevetuckner <stevetuck...@usfamily.net>
Date: Thu, 20 Oct 2005 03:08:40 +0900
Local: Wed, Oct 19 2005 2:08 pm
Subject: Re: usage 0.0.4 - The IO edition

Adam Sanderson wrote:
>This looks really handy, could you post a few more examples?
>  .adam

I am not sure what you would like to see for examples. Including with
the gem are 12 sample programs to show off its capabilities. But here
are a few of them. Here is one that exercises almost all of its
capabilities:

Usage.new "[-y] [-x excluded_tags] (-z ztag) (-w warning_arg) <infile
%num_times >outfile files..." do |u|
    .....
end

In this example, the -y and -x options are optional. The -z option and
its argument ztag are required as well as the -w and its argument
warning_arg.  Past the options, there are three required non-option
arguments and beyond that a list of 0 or more files. The options are
accessed via u#dash_ w,x,y, and z (and are nil if they weren't
specified). The arguments for the options are accessed via u#
exclueded_tags, ztag and warning_arg. The arguments themselves are
accessed via u# infile, num_times, outfile and files.  infile is checked
to see if it is a file and opened if it is. Its value is returned as a
File object..  num_times is checked to see if it is an integer and it
returns an Integer object.  outfile opens an file for writing and
returns a File object. files returns an array of strings.

Beyond that example above, you can create your own (type sequences --
like < or >) for your own custom argument processing. Below is an
example of how to do that:

    #
    # This example is taken from the built-in class for arguments that
are writable files
    # that don't want to be overwritten
    #

    # first define the file exists exception class
    class FileOutputExistsError < UsageMod::Error
        attr_reader :filename
        def initialize(filename)
            @filename = filename
            super("output file exists: '#{filename}'")
        end
    end

    # next define the argument parser plugin
    class FileOutputQueryPlugin < UsageMod::ArgumentParserPlugin
        def initialize(usage_ui, str)
            if FileTest.exist?(str) then
                raise FileOutputExistsError.new(str) if
usage_ui.ask_yes_no(OVERWRITE_QUERY % str, NO_RESPONSE) == NO_RESPONSE
            end
            @value = File.open(str, "w")
        end

        def close
            @value.close
        end
    end

    # lastly attach that parser to the character sequence '>?'
    UsageMod::Base.add_type_handler(">?", FileOutputQueryPlugin)

Thanks for your interest,

Steve Tuckner


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google