Skip to content

Commit

Permalink
1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
rkumar committed Jun 24, 2010
1 parent 6366346 commit 3c2915f
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
45 changes: 45 additions & 0 deletions 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
47 changes: 47 additions & 0 deletions 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

0 comments on commit 3c2915f

Please sign in to comment.