clap 0.0.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/clap.gemspec +9 -9
- data/lib/clap.rb +0 -2
- data/test/clap_test.rb +11 -0
- metadata +31 -52
- data/README.markdown +0 -76
data/clap.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
|
-
s.name
|
3
|
-
s.version
|
4
|
-
s.summary
|
5
|
-
s.description
|
6
|
-
s.authors
|
7
|
-
s.email
|
8
|
-
s.homepage
|
9
|
-
s.files
|
10
|
-
s.add_development_dependency "cutest"
|
2
|
+
s.name = "clap"
|
3
|
+
s.version = "1.0.0"
|
4
|
+
s.summary = "Command line argument parsing for simple applications."
|
5
|
+
s.description = "Clap is a small library that can be bundled with your command line application. It covers the simple case of executing code based on the flags or parameters passed."
|
6
|
+
s.authors = ["Michel Martens"]
|
7
|
+
s.email = ["michel@soveran.com"]
|
8
|
+
s.homepage = "http://github.com/soveran/clap"
|
9
|
+
s.files = Dir[ "LICENSE", "README.markdown", "Rakefile", "lib/**/*.rb", "*.gemspec", "test/**/*.rb" ]
|
10
|
+
s.add_development_dependency "cutest"
|
11
11
|
end
|
data/lib/clap.rb
CHANGED
data/test/clap_test.rb
CHANGED
@@ -30,3 +30,14 @@ test "extract flags with no parameters" do
|
|
30
30
|
result = Clap.run %w(a b -x c), "-x" => lambda {}
|
31
31
|
assert result == %w(a b c)
|
32
32
|
end
|
33
|
+
|
34
|
+
test "use a method instead of a lambda" do
|
35
|
+
class Foo
|
36
|
+
def self.bar(flag)
|
37
|
+
assert flag == "y"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
result = Clap.run %w(a b -x y c), "-x" => Foo.method(:bar)
|
42
|
+
assert result == %w(a b c)
|
43
|
+
end
|
metadata
CHANGED
@@ -1,83 +1,62 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: clap
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
version: 0.0.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Michel Martens
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-03-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: cutest
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2152083100 !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
- 0
|
30
|
-
- 1
|
31
|
-
version: "0.1"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
32
22
|
type: :development
|
33
|
-
|
34
|
-
|
35
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2152083100
|
25
|
+
description: Clap is a small library that can be bundled with your command line application.
|
26
|
+
It covers the simple case of executing code based on the flags or parameters passed.
|
27
|
+
email:
|
36
28
|
- michel@soveran.com
|
37
29
|
executables: []
|
38
|
-
|
39
30
|
extensions: []
|
40
|
-
|
41
31
|
extra_rdoc_files: []
|
42
|
-
|
43
|
-
files:
|
32
|
+
files:
|
44
33
|
- LICENSE
|
45
|
-
- README.markdown
|
46
34
|
- Rakefile
|
47
35
|
- lib/clap.rb
|
48
36
|
- clap.gemspec
|
49
37
|
- test/clap_test.rb
|
50
|
-
has_rdoc: true
|
51
38
|
homepage: http://github.com/soveran/clap
|
52
39
|
licenses: []
|
53
|
-
|
54
40
|
post_install_message:
|
55
41
|
rdoc_options: []
|
56
|
-
|
57
|
-
require_paths:
|
42
|
+
require_paths:
|
58
43
|
- lib
|
59
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
45
|
none: false
|
61
|
-
requirements:
|
62
|
-
- -
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
|
65
|
-
|
66
|
-
version: "0"
|
67
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
51
|
none: false
|
69
|
-
requirements:
|
70
|
-
- -
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
|
73
|
-
- 0
|
74
|
-
version: "0"
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
75
56
|
requirements: []
|
76
|
-
|
77
57
|
rubyforge_project:
|
78
|
-
rubygems_version: 1.
|
58
|
+
rubygems_version: 1.8.10
|
79
59
|
signing_key:
|
80
60
|
specification_version: 3
|
81
61
|
summary: Command line argument parsing for simple applications.
|
82
62
|
test_files: []
|
83
|
-
|
data/README.markdown
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
Clap
|
2
|
-
====
|
3
|
-
|
4
|
-
Command line argument parsing for simple applications.
|
5
|
-
|
6
|
-
Description
|
7
|
-
-----------
|
8
|
-
|
9
|
-
Clap is a small library that can be bundled with your command line application.
|
10
|
-
It covers the simple case of executing code based on the flags or parameters
|
11
|
-
passed, and it does so with just under 30 lines of code.
|
12
|
-
|
13
|
-
Usage
|
14
|
-
-----
|
15
|
-
|
16
|
-
Using Clap is simple: just pass `ARGV` and a hash of flags, and it will extract
|
17
|
-
the arguments as needed.
|
18
|
-
|
19
|
-
Clap.run ARGV,
|
20
|
-
"-a" => lambda { |param| ... },
|
21
|
-
"-b" => lambda { ... }
|
22
|
-
|
23
|
-
To better illustrate the usage, in the following examples `ARGV` is replaced by
|
24
|
-
an array of strings.
|
25
|
-
|
26
|
-
If you want your command line application to require a file or display a
|
27
|
-
version number, you can configure it like this:
|
28
|
-
|
29
|
-
Clap.run %w(-r foo -v),
|
30
|
-
"-r" => lambda { |file| require file },
|
31
|
-
"-v" => lambda { puts VERSION }
|
32
|
-
|
33
|
-
This will detect the `-r` or `-v` flags and act accordingly. Note that it will
|
34
|
-
also read the necessary number of parameters for each flag based on the arity
|
35
|
-
of the passed lambda.
|
36
|
-
|
37
|
-
Another example, for an application that takes a `-v` flag and also a list of
|
38
|
-
files:
|
39
|
-
|
40
|
-
files = Clap.run %w(-v foo bar),
|
41
|
-
"-v" => lambda { puts VERSION }
|
42
|
-
|
43
|
-
files == %w(foo bar)
|
44
|
-
|
45
|
-
If you are in doubt, check the tests for the different use cases.
|
46
|
-
|
47
|
-
Installation
|
48
|
-
------------
|
49
|
-
|
50
|
-
$ gem install clap
|
51
|
-
|
52
|
-
License
|
53
|
-
-------
|
54
|
-
|
55
|
-
Copyright (c) 2010 Michel Martens
|
56
|
-
|
57
|
-
Permission is hereby granted, free of charge, to any person
|
58
|
-
obtaining a copy of this software and associated documentation
|
59
|
-
files (the "Software"), to deal in the Software without
|
60
|
-
restriction, including without limitation the rights to use,
|
61
|
-
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
62
|
-
copies of the Software, and to permit persons to whom the
|
63
|
-
Software is furnished to do so, subject to the following
|
64
|
-
conditions:
|
65
|
-
|
66
|
-
The above copyright notice and this permission notice shall be
|
67
|
-
included in all copies or substantial portions of the Software.
|
68
|
-
|
69
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
70
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
71
|
-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
72
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
73
|
-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
74
|
-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
75
|
-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
76
|
-
OTHER DEALINGS IN THE SOFTWARE.
|