pwqgen.rb 0.0.3.pre → 0.0.3.pre.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,7 +12,7 @@ Options:
12
12
  <length>: Number of words in the passphrase. [default: 3]
13
13
  "
14
14
 
15
- require 'docopt'
15
+ require 'pwqgen/docopt'
16
16
 
17
17
  options = Docopt(doc, Pwqgen::VERSION)
18
18
 
@@ -0,0 +1,132 @@
1
+ # Copyright (c) 2012 Vladimir Keleshev <vladimir@keleshev.com>, Alex Speller <alex@alexspeller.com>
2
+
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ # this software and associated documentation files (the "Software"), to deal in
5
+ # the Software without restriction, including without limitation the rights to
6
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ # of the Software, and to permit persons to whom the Software is furnished to do
8
+ # so, subject to the following conditions:
9
+
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require 'getoptlong'
22
+
23
+ class Docopt
24
+ attr_reader :docopts
25
+
26
+ class UnknownOptionError < StandardError; end
27
+
28
+ class Option
29
+ attr_reader :short, :long, :argcount, :value
30
+
31
+ def initialize parse
32
+ @argcount = 0
33
+ options, _, description = parse.strip.partition(' ')
34
+ options = options.sub(',', ' ').sub('=', ' ')
35
+
36
+ for s in options.split
37
+ if s.start_with? '--'
38
+ @long = s
39
+ elsif s.start_with? '-'
40
+ @short = s
41
+ else
42
+ @argcount = 1
43
+ end
44
+ end
45
+
46
+ if @argcount == 1
47
+ matched = description.scan(/\[default: (.*)\]/)[0]
48
+ @value = matched ? matched[0] : nil
49
+ end
50
+ end
51
+
52
+ def set_value val
53
+ if argcount.zero?
54
+ @value = true
55
+ else
56
+ @value = val
57
+ end
58
+ end
59
+
60
+ def synonyms
61
+ ([short, long] + symbols).compact
62
+ end
63
+
64
+ def symbols
65
+ [short, long].compact.map do |name|
66
+ name.gsub(/^-+/, '').to_sym
67
+ end
68
+ end
69
+
70
+ def getopt
71
+ [long, short, argcount].compact
72
+ end
73
+
74
+ def inspect
75
+ "#<Docopt::Option short: #{short}, long: #{long}, argcount: #{argcount}, value: #{value}>"
76
+ end
77
+
78
+ def == other
79
+ self.inspect == other.inspect
80
+ end
81
+ end
82
+
83
+
84
+ def initialize(doc, version=nil, help=true)
85
+ @docopts = doc.split(/^ *-|\n *-/)[1..-1].map do |line|
86
+ Option.new('-' + line)
87
+ end
88
+
89
+ GetoptLong.new(*docopts.map(&:getopt)).each do |opt, arg|
90
+ docopt_option = option(opt)
91
+ if help and (opt == '--help' or opt == '-h')
92
+ puts doc.strip
93
+ exit
94
+ elsif version and opt == '--version'
95
+ puts version
96
+ exit
97
+ else
98
+ docopt_option.set_value arg
99
+ end
100
+ end
101
+ end
102
+
103
+ def option name
104
+ option = @docopts.detect do |docopt|
105
+ docopt.synonyms.include?(name)
106
+ end
107
+ raise UnknownOptionError.new("#{name} option not found") unless option
108
+ option
109
+ end
110
+
111
+
112
+
113
+ def value name
114
+ option(name).value
115
+ end
116
+ alias_method :[], :value
117
+
118
+ def size
119
+ @docopts.size
120
+ end
121
+
122
+ def inspect
123
+ @docopts.map do |option|
124
+ "#{option.short} #{option.long}=#{option.value.inspect}".strip
125
+ end.join("\n")
126
+ end
127
+ end
128
+
129
+ # Convenience method for Docopt.parse
130
+ def Docopt *args
131
+ Docopt.new *args
132
+ end
@@ -1,3 +1,3 @@
1
1
  module Pwqgen
2
- VERSION = "0.0.3.pre"
2
+ VERSION = "0.0.3.pre.1"
3
3
  end
@@ -16,8 +16,9 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ['lib']
18
18
 
19
- s.required_ruby_version = '>=1.9.2'
20
- s.add_runtime_dependency('docopt', "~>0.0.4")
19
+ s.required_ruby_version = '>= 1.9.2'
20
+ s.required_rubygems_version = ">= 1.3.6"
21
+ #s.add_runtime_dependency('docopt', "~> 0.0.4")
21
22
 
22
23
  s.add_development_dependency 'rake'
23
24
  s.add_development_dependency 'rspec'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pwqgen.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.pre
4
+ version: 0.0.3.pre.1
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-29 00:00:00.000000000 Z
12
+ date: 2012-07-01 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: docopt
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: 0.0.4
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: 0.0.4
30
14
  - !ruby/object:Gem::Dependency
31
15
  name: rake
32
16
  requirement: !ruby/object:Gem::Requirement
@@ -133,6 +117,7 @@ files:
133
117
  - features/step_definitions/pwqgen.rb_steps.rb
134
118
  - features/support/env.rb
135
119
  - lib/pwqgen.rb
120
+ - lib/pwqgen/docopt.rb
136
121
  - lib/pwqgen/pwqgen.rb
137
122
  - lib/pwqgen/version.rb
138
123
  - lib/pwqgen/wordlist.rb
@@ -154,9 +139,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
139
  required_rubygems_version: !ruby/object:Gem::Requirement
155
140
  none: false
156
141
  requirements:
157
- - - ! '>'
142
+ - - ! '>='
158
143
  - !ruby/object:Gem::Version
159
- version: 1.3.1
144
+ version: 1.3.6
160
145
  requirements: []
161
146
  rubyforge_project:
162
147
  rubygems_version: 1.8.23