Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

1.0.4

  • Loading branch information...
commit 3c2915f01e583c0bd35f83097a060fbf626ff514 1 parent 6366346
@rkumar authored
Showing with 92 additions and 0 deletions.
  1. +45 −0 tests/test.rb
  2. +47 −0 tests/test1.rb
View
45 tests/test.rb
@@ -0,0 +1,45 @@
+#!/usr/bin/env ruby -w
+require 'subcommand'
+
+if __FILE__ == $PROGRAM_NAME
+ include Subcommands
+ options = {}
+ appname = File.basename($0)
+ # global is optional
+ #global_options do |opts|
+ #opts.banner = "Usage: #{appname} [options] [subcommand [options]]"
+ #opts.description = "Stupid program that does something"
+ #opts.separator ""
+ #opts.separator "Global options are:"
+ #opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
+ #options[:verbose] = v
+ #end
+ #end
+ # define a command
+ command :foo, :goo do |opts|
+ opts.banner = "Usage: foo [options]"
+ opts.description = "desc for foo"
+ opts.on("-f", "--[no-]force", "force verbosely") do |v|
+ options[:force] = v
+ end
+ end
+ command :baz do |opts|
+ opts.banner = "Usage: baz [options]"
+ opts.description = "desc for baz"
+ opts.on("-q", "--[no-]quiet", "quietly run ") do |v|
+ options[:quiet] = v
+ end
+ end
+ alias_command :bar, 'baz'
+ alias_command :boo, 'foo', '--force'
+ alias_command :zoo, 'foo', 'ruby'
+
+ # do the parsing.
+ cmd = opt_parse()
+
+ puts "cmd: #{cmd}"
+ puts "options ......"
+ p options
+ puts "ARGV:"
+ p ARGV
+end
View
47 tests/test1.rb
@@ -0,0 +1,47 @@
+#!/usr/bin/env ruby -w
+######################################
+require 'subcommand'
+
+if __FILE__ == $PROGRAM_NAME
+ include Subcommands
+ options = {}
+ appname = File.basename($0)
+ # global is optional
+ global_options do |opts|
+ opts.banner = "Usage: #{appname} [options] [subcommand [options]]"
+ opts.description = "Stupid program that does something"
+ opts.separator ""
+ opts.separator "Global options are:"
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
+ options[:verbose] = v
+ end
+ end
+ add_help_option
+ # define a command
+ command :foo, :goo do |opts|
+ opts.banner = "Usage: foo [options]"
+ opts.description = "desc for foo"
+ opts.on("-f", "--[no-]force", "force verbosely") do |v|
+ options[:force] = v
+ end
+ end
+ command :baz do |opts|
+ opts.banner = "Usage: baz [options]"
+ opts.description = "desc for baz"
+ opts.on("-q", "--[no-]quiet", "quietly run ") do |v|
+ options[:quiet] = v
+ end
+ end
+ alias_command :bar, 'baz'
+ alias_command :boo, 'foo', '--force'
+ alias_command :zoo, 'foo', 'ruby'
+
+ # do the parsing.
+ cmd = opt_parse()
+
+ puts "cmd: #{cmd}"
+ puts "options ......"
+ p options
+ puts "ARGV:"
+ p ARGV
+end
Please sign in to comment.
Something went wrong with that request. Please try again.