svn-campfire-notifier 0.2.1 → 0.2.2
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/lib/option_parser.rb +34 -0
- metadata +4 -3
@@ -0,0 +1,34 @@
|
|
1
|
+
# Parser for command line options
|
2
|
+
class OptionParser
|
3
|
+
# Parses ARGV from a Ruby script and returns options as a hash and
|
4
|
+
# arguments as a list.
|
5
|
+
#
|
6
|
+
# OptionParser.parse(%w(create --username manfred)) #=>
|
7
|
+
# [{"username"=>"manfred"}, ["create"]]
|
8
|
+
def self.parse(argv)
|
9
|
+
return [{},[]] if argv.empty?
|
10
|
+
|
11
|
+
options = {}
|
12
|
+
rest = []
|
13
|
+
switch = nil
|
14
|
+
|
15
|
+
for value in argv
|
16
|
+
# value is a switch
|
17
|
+
if value[0] == 45
|
18
|
+
switch = value.slice((value[1] == 45 ? 2 : 1)..-1)
|
19
|
+
options[switch] = nil
|
20
|
+
else
|
21
|
+
if switch
|
22
|
+
# we encountered another switch so this
|
23
|
+
# value belongs to the last switch
|
24
|
+
options[switch] = value
|
25
|
+
switch = nil
|
26
|
+
else
|
27
|
+
rest << value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
[options, rest]
|
33
|
+
end
|
34
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: svn-campfire-notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Manfred Stienstra
|
@@ -57,6 +57,7 @@ extra_rdoc_files:
|
|
57
57
|
- LICENSE
|
58
58
|
files:
|
59
59
|
- LICENSE
|
60
|
+
- lib/option_parser.rb
|
60
61
|
- lib/svn_campfire_notifier.rb
|
61
62
|
- lib/svn_campfire_notifier/core_ext.rb
|
62
63
|
- lib/svn_campfire_notifier/google_image.rb
|