pwqgen.rb 0.0.3 → 0.0.4

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/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ = 0.0.4 / 2012-10-14
2
+ * Improved CLI option parsing.
3
+ * Reverted to vendor docopt.rb.
4
+
1
5
  = 0.0.3 / 2012-07-09
2
6
 
3
7
  * Improved CLI output.
@@ -2,23 +2,34 @@
2
2
 
3
3
  require 'pwqgen/version'
4
4
  require 'pwqgen'
5
+ require 'docopt'
5
6
 
6
- doc = "Usage: pwqgen.rb [options] [<length>]
7
+ doc = <<DOCOPT
8
+ Generate a random pronouncable passphrase.
9
+
10
+ Usage:
11
+ #{__FILE__} [LENGTH]
12
+ #{__FILE__} [-h | --help]
13
+ #{__FILE__} [-v | --version]
14
+
15
+ Arguments:
16
+ LENGTH Number of words in the passphrase. [default: 3]
7
17
 
8
18
  Options:
9
19
  -h, --help show this help message and exit
10
20
  -v, --version show version and exit
11
21
 
12
- <length>: Number of words in the passphrase. [default: 3]
13
- "
14
-
15
- require 'pwqgen/docopt'
22
+ DOCOPT
16
23
 
17
- options = Docopt(doc, Pwqgen::VERSION)
24
+ begin
25
+ options = Docopt::docopt(doc, version: Pwqgen::VERSION)
18
26
 
19
- if ARGV.length > 0 && ARGV[0].to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) then
20
- puts Pwqgen.generate(ARGV[0].to_i)
21
- else
22
- puts Pwqgen.generate
27
+ if ARGV.length > 0 && ARGV[0].to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) then
28
+ puts Pwqgen.generate(ARGV[0].to_i)
29
+ else
30
+ puts Pwqgen.generate
31
+ end
32
+ rescue Docopt::Exit => e
33
+ puts e.message
23
34
  end
24
35
 
@@ -1,3 +1,3 @@
1
1
  module Pwqgen
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
 
19
19
  s.required_ruby_version = '>= 1.9.2'
20
20
  s.required_rubygems_version = ">= 1.3.6"
21
- #s.add_runtime_dependency('docopt', "~> 0.0.4")
21
+ s.add_runtime_dependency('docopt', "~> 0.5.0")
22
22
 
23
23
  s.add_development_dependency 'rake'
24
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
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-09 00:00:00.000000000 Z
12
+ date: 2012-10-14 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.5.0
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.5.0
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: rake
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -117,7 +133,6 @@ files:
117
133
  - features/step_definitions/pwqgen.rb_steps.rb
118
134
  - features/support/env.rb
119
135
  - lib/pwqgen.rb
120
- - lib/pwqgen/docopt.rb
121
136
  - lib/pwqgen/pwqgen.rb
122
137
  - lib/pwqgen/version.rb
123
138
  - lib/pwqgen/wordlist.rb
@@ -144,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
159
  version: 1.3.6
145
160
  requirements: []
146
161
  rubyforge_project:
147
- rubygems_version: 1.8.23
162
+ rubygems_version: 1.8.24
148
163
  signing_key:
149
164
  specification_version: 3
150
165
  summary: pwqgen in Ruby
@@ -154,4 +169,3 @@ test_files:
154
169
  - features/support/env.rb
155
170
  - spec/lib/pwqgen_spec.rb
156
171
  - spec/spec_helper.rb
157
- has_rdoc:
@@ -1,132 +0,0 @@
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