From: Jim Freeze Date: 2006-01-25T15:31:51+09:00 Subject: Re: Python / ruby command line script? --Apple-Mail-10-949705876 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Hi On Jan 24, 2006, at 11:08 AM, Paatsch, Bernd wrote: > Hello, > > I am a newbie to Ruby. However I have used python a little bit. > I like to convert my python scripts to ruby. One of them is a > command line > script taking input and switches. > Is there something equivalent in ruby? Yes, but Ruby also has something much better - CommandLine - it's the rails equivalent for commandline apps. :) > Generate something > Usage: python xyz.py [options] [source] [destination] > Options: > -h, --help show help > Examples: xyz.py input.csv output.html #!/usr/bin/env ruby require 'rubygems' require 'commandline' class App < CommandLine::Application def initialize synopsis "[options] [source] [destination]" option :help expected_args :source :destination end def main # your code here end end > """ > > def main(argv): > """Main Entry Point """ > try: > opts, args = getopt.getopt(argv, "h", ["help"]) > except getopt.GetoptError: > usage() > sys.exit(2) > > for opt, arg in opts: if opt in ("-h", "--help"): > usage() sys.exit() > > try: > source = sys.argv[1] > global destination > destination = sys.argv[2] > except: > usage() > sys.exit(2) > > seleniumHtmlGenerator(source) > > > if __name__ == "__main__": > main(sys.argv[1:]) Jim Freeze --Apple-Mail-10-949705876--