getopt 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/CHANGES +2 -0
  2. data/MANIFEST +10 -0
  3. data/README +57 -0
  4. data/test/tc_getopt_std.rb +70 -0
  5. metadata +45 -0
data/CHANGES ADDED
@@ -0,0 +1,2 @@
1
+ == 5-Oct-2005
2
+ * Initial commit
data/MANIFEST ADDED
@@ -0,0 +1,10 @@
1
+ CHANGES
2
+ MANIFEST
3
+ install.rb
4
+ getopt.gemspec
5
+
6
+ examples/test_std.rb
7
+
8
+ lib/getopt/std.rb
9
+
10
+ test/tc_getopt_std.rb
data/README ADDED
@@ -0,0 +1,57 @@
1
+ == Description
2
+ Implements a simple Getopt::Std class for command line parsing. It will
3
+ eventually add a drop-in replacement for getopt-long as well.
4
+
5
+ == Prerequisites
6
+ Ruby 1.8.0 or later.
7
+
8
+ == Installation
9
+ === Standard Installation
10
+ ruby test/tc_getopt_std.rb
11
+ ruby install.rb
12
+ === Gem Installation
13
+ ruby test/tc_getopt_std.rb
14
+ ruby getopt.gemspec
15
+ gem install getopt-x-y-z.gem # Where x-y-z is a version
16
+
17
+ == Synopsis
18
+ require "getopt/std"
19
+
20
+ # Look for -o with argument, and -I and -D boolean arguments
21
+ opt = Getopt::Std.getopts("o:ID")
22
+
23
+ if opt["I"]
24
+ # Do something if -I passed
25
+
26
+ if opt["D"]
27
+ # Do something if -D passed
28
+
29
+ if opt["o"]
30
+ case opt["o"]
31
+ # blah, blah, blah
32
+ end
33
+ end
34
+
35
+ == Future Plans
36
+ * Add a replacement for Getopt::Long.
37
+
38
+ == Known Bugs
39
+ None that I'm aware of. If you find any, please log them on the project
40
+ page at http://www.rubyforge.org/projects/shards.
41
+
42
+ == Warranty
43
+ This package is provided "as is" and without any express or
44
+ implied warranties, including, without limitation, the implied
45
+ warranties of merchantability and fitness for a particular purpose.
46
+
47
+ == License
48
+ Ruby's
49
+
50
+ == Copyright
51
+ (C) 2005, Daniel J. Berger
52
+ All Rights Reserved
53
+
54
+ == Author
55
+ Daniel J. Berger
56
+ djberg96 at gmail.com
57
+ imperator on IRC (freenode)
@@ -0,0 +1,70 @@
1
+ ########################################################
2
+ # tc_getopt_std.rb
3
+ #
4
+ # Test suite for the Getopt::Std class.
5
+ ########################################################
6
+ base = File.basename(Dir.pwd)
7
+
8
+ if base == "test" || base =~ /getopt/
9
+ Dir.chdir("..") if base == "test"
10
+ $LOAD_PATH.unshift(Dir.pwd + "/lib")
11
+ Dir.chdir("test") rescue nil
12
+ end
13
+
14
+ require "test/unit"
15
+ require "getopt/std"
16
+ include Getopt
17
+
18
+ class TC_Getopt_Std < Test::Unit::TestCase
19
+ def setup
20
+ @basic_opts = %w/-I -D/
21
+ @mixed_opts = %w/-o hello -I -D/
22
+ @extra_opts = %w/-I -D -X/
23
+ end
24
+
25
+ def test_version
26
+ assert_equal("1.0.0", Std::VERSION)
27
+ end
28
+
29
+ def test_getopts_basic
30
+ ARGV.push(*@basic_opts)
31
+ assert_respond_to(Std, :getopts)
32
+ assert_nothing_raised{ Std.getopts("ID") }
33
+ assert_kind_of(Hash, Std.getopts("ID"))
34
+ assert_equal({"I"=>true, "D"=>true}, Std.getopts("ID"))
35
+ end
36
+
37
+ def test_getopts_advanced
38
+ ARGV.push(*@mixed_opts)
39
+ assert_nothing_raised{ Std.getopts("o:ID") }
40
+ assert_equal({"o"=>"hello", "I"=>true, "D"=>true}, Std.getopts("o:ID"))
41
+ end
42
+
43
+ def test_getopts_no_args
44
+ assert_nothing_raised{ Std.getopts("ID") }
45
+ assert_equal({}, Std.getopts("ID"))
46
+ assert_nil(Std.getopts("ID")["I"])
47
+ assert_nil(Std.getopts("ID")["D"])
48
+ end
49
+
50
+ def test_getopts_expected_errors_missing_arg
51
+ ARGV.push(*@basic_opts)
52
+ assert_raises(StdError){ Std.getopts("I:D") }
53
+ assert_raises(StdError){ Std.getopts("ID:") }
54
+ end
55
+
56
+ def test_getopts_expected_errors_extra_arg
57
+ ARGV.push(*@extra_opts)
58
+ assert_raises(StdError){ Std.getopts("ID") }
59
+ end
60
+
61
+ def test_getopts_expected_errors_basic
62
+ assert_raises(ArgumentError){ Std.getopts }
63
+ assert_raises(NoMethodError){ Std.getopts(0) }
64
+ assert_raises(NoMethodError){ Std.getopts(nil) }
65
+ end
66
+
67
+ def teardown
68
+ ARGV.clear
69
+ end
70
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: getopt
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.0.0
7
+ date: 2005-10-06 00:00:00 -06:00
8
+ summary: Getopt::Std for Ruby
9
+ require_paths:
10
+ - lib
11
+ email: djberg96@gmail.com
12
+ homepage: http://www.rubyforge.org/projects/shards
13
+ rubyforge_project:
14
+ description: Getopt::Std for Ruby
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ -
22
+ - ">"
23
+ - !ruby/object:Gem::Version
24
+ version: 0.0.0
25
+ version:
26
+ platform: ruby
27
+ signing_key:
28
+ cert_chain:
29
+ authors:
30
+ - Daniel J. Berger
31
+ files:
32
+ - CHANGES
33
+ - MANIFEST
34
+ - README
35
+ - test/tc_getopt_std.rb
36
+ test_files:
37
+ - test/tc_getopt_std.rb
38
+ rdoc_options: []
39
+ extra_rdoc_files:
40
+ - README
41
+ - CHANGES
42
+ executables: []
43
+ extensions: []
44
+ requirements: []
45
+ dependencies: []