cmdparse-2.0.5/ 0000755 0000041 0000041 00000000000 11764730765 013364 5 ustar www-data www-data cmdparse-2.0.5/README 0000644 0000041 0000041 00000002677 11764730765 014260 0 ustar www-data www-data cmdparse - an advanced command line parser using optparse which has support for commands Copyright (C) 2004-2012 Thomas Leitner = Description Some new programs use a "command style" command line. Examples for such programs are the "svn" program from Subversion and the "gem" program from Rubygems. The standard Ruby distribution has no library to create programs that use such a command line interface. This library, cmdparse, can be used to create such a command line interface. Internally it uses optparse or any other option parser library to parse options and it provides a nice API for specifying commands. = License GNU LGPLv3 - see COPYING.LESSER for the LGPL and COPYING for the GPL = Dependencies none = Installation The preferred way of installing cmdparse is via RubyGems: $ gem install cmdparse If you do not have RubyGems installed, but Rake, you can use the following command: $ rake install If you have neither RubyGems nor Rake, use these commands: $ ruby setup.rb config $ ruby setup.rb setup $ ruby setup.rb install = Documentation You can build the documentation by invoking $ rake doc This builds the API and the additional documentation. The additional documentation needs webgen >=0.3.5 (webgen.rubyforge.org) for building. = Example There is an example of how to use cmdparse in the +net.rb+ file. = Contact Author: Thomas Leitner * Web: http://cmdparse.rubyforge.org * e-Mail: t_leitner@gmx.at * GPG Key-Id: 0xD942E7F6 cmdparse-2.0.5/doc/ 0000755 0000041 0000041 00000000000 11764730765 014131 5 ustar www-data www-data cmdparse-2.0.5/doc/config.yaml 0000644 0000041 0000041 00000000042 11764730765 016256 0 ustar www-data www-data PageHandler: validator: xmllint cmdparse-2.0.5/doc/plugin/ 0000755 0000041 0000041 00000000000 11764730765 015427 5 ustar www-data www-data cmdparse-2.0.5/doc/plugin/extract.rb 0000644 0000041 0000041 00000001544 11764730765 017432 0 ustar www-data www-data module CmdparsePlugins class ExtractTag < Tags::DefaultTag summary "Extracts lines from a file" depends_on 'Tags' add_param 'file', nil, 'the file from which to read the lines' add_param 'lines', nil, 'the lines which should be read (Range)' set_mandatory 'file' set_mandatory 'lines' def initialize super @processOutput = false register_tag( 'extract' ) end def process_tag( tag, node, refNode ) data = File.readlines( get_param( 'file' ) ).unshift( 'empty null line' )[get_param( 'lines' )] out = '
' << get_param( 'lines' ).collect {|n| "#{n} | '
out << '' << data.collect {|line| "#{CGI::escapeHTML(line)}" }.to_s << ' | '
out << '
class TestCmd < CmdParse::Command def initialize super('test', true) self.add_command(TestSubCmd.new) end end class TestSubCmd < CmdParse::Command def initialize super('sub',false) end def execute (args) puts "Hallo #{args}" end end cmd = CmdParse::CommandParser.new( true ) cmd.add_command(TestCmd.new)Defining command using the basic @CmdParse::Command@ class:
cmd = CmdParse::CommandParser.new( true ) testcmd = CmdParse::Command.new( 'test', true ) testcmd.short_desc = "Short desc" cmd.add_command( testcmd ) sub = CmdParse::Command.new( 'sub', false ) sub.short_desc = "Add an IP address" sub.set_execution_block do |args| puts "Hallo #{args}" end testcmd.add_command( sub )h2(#tutorial). Tutorial The complete code for this example can be found in the file @net.rb@ of the @cmdparse@ package! This tutorial produces a small @net@ application which can add, delete and list IP adresses and show 'network statistics'. The shown code fragments do not include the whole program. So, instead of writing all the code yourself, just look at the code fragments first and then use the include @net.rb@ file for running the program. h3. Require statements Create a new new file and write the necessary @require@ statements.
$ ruby net.rb --verbose ipaddr add 192.168.0.1 193.150.0.1*
$ ruby net.rbyou get an error because you did not specify any command. However, when you type
$ ruby net.rb ipaddryou do not get an error! Why? As the @ipaddr@ command takes subcommands there should be an additional command name (e.g. @list@) on the command line. However, as the @list@ command is the default command for @ipaddr@ you do not need to type it. *By the way:* You get the same output if you type
$ ruby net.rb ipWhy? As partial command matching is used for the top level commands, the shortest unambiguous name for a command can be used. As there is no other command starting with @ip@ (or even with the letter @i@), it is sufficient to write the above to select the @ipaddr@ command. *Notice:* The options of a command which does not take subcommands do not need to be at the front; they can be anywhere, like this
$ ruby test.rb --verbose mycommand file1 file2 --recursive file3cmdparse-2.0.5/doc/src/meta.info 0000644 0000041 0000041 00000000137 11764730765 016524 0 ustar www-data www-data api.html: dest: rdoc/index.html title: API Reference orderInfo: 7 inMenu: true cmdparse-2.0.5/doc/src/download.page 0000644 0000041 0000041 00000001275 11764730765 017372 0 ustar www-data www-data --- title: Download & Installation inMenu: true orderInfo: 4 --- h2. Download The newest version of cmdparse can be downloaded from Rubyforge. Homepage: "cmdparse.rubyforge.org":http://cmdparse.rubyforge.org
$ gem install cmdparseIf you do not have RubyGems installed, but Rake, you can use the following command:
$ rake installIf you have neither RubyGems nor Rake, use these commands:
$ ruby setup.rb config $ ruby setup.rb setup $ ruby setup.rb installcmdparse-2.0.5/doc/src/logo.png 0000644 0000041 0000041 00000030250 11764730765 016366 0 ustar www-data www-data PNG IHDR <q sBIT|d tEXtSoftware www.inkscape.org< IDATxwx\g?LE3uɖ-$N '^ػ}],e/K]K pTKV5H{=1Xekd[<ǞsWm ,Zf