dry_option_parser 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb4ac599313f2cd2b9ea092d8445383dc8e50d9c
4
- data.tar.gz: afea1a0ec1046c7c01f26f071fab2bc17ff3d646
3
+ metadata.gz: 1f2ef69e05bb350dc77b839f08832c4dce09f5c1
4
+ data.tar.gz: ef5e9b6c05fe8bfa426a5d71dbc2f52ffbf4bb15
5
5
  SHA512:
6
- metadata.gz: df699b0276b84447a9e6cd48061507f84455a95705b8e506fcde07baf9f93563ee798d1fb81d9973efaf4c2207c8bff3f32479d0a07f9e82f31bd7c3bdf1a8a2
7
- data.tar.gz: 3dc3f49e41a18ff35ebc19a04ca618867a0c1d73280dbfb55de7aab0c16fad9c49302ff93597c3ef15bea0172c3dfa81705a40e7419dbef3411983633ed07fd3
6
+ metadata.gz: 65a62be0815faa7b0c5c6641a571450340fa78997402842d577ab674718e99b7d88cf30e2491f014cb30fa91e6747907aaa31ce62c738f6eff31c5b0fcfc76e7
7
+ data.tar.gz: a2a757c8a66efa38d2dfefca8a6d25ca8c8f244aa94dbbd1a00adb97b0a6db02ff49760ce53982a82975e73f158f16f421d8084ac8e597ee4d36c9c5fad074c3
@@ -17,24 +17,24 @@ opt_parser = cli_options(options) do
17
17
  codes = %w[iso-2022-jp shift_jis euc-jp utf8 binary]
18
18
  code_aliases = { "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
19
19
 
20
- self.banner = "Usage: example.rb [@options]"
20
+ self.banner = "Usage: example.rb [options]"
21
21
 
22
22
  separator ""
23
- separator "Specific @options:"
23
+ separator "Specific options:"
24
24
 
25
25
  # Mandatory argument.
26
- assign("library", "-r", "--require LIBRARY",
26
+ on("-r", "--require LIBRARY",
27
27
  "Require the LIBRARY before executing your script") do |lib|
28
- @options.library << lib
28
+ options.library << lib
29
29
  end
30
30
 
31
31
  # Optional argument; multi-line description.
32
32
  on("-i", "--inplace [EXTENSION]",
33
33
  "Edit ARGV files in place",
34
34
  " (make backup if EXTENSION supplied)") do |ext|
35
- @options.inplace = true
36
- @options.extension = ext || ''
37
- @options.extension.sub!(/\A\.?(?=.)/, ".") # Ensure extension begins with dot.
35
+ options.inplace = true
36
+ options.extension = ext || ''
37
+ options.extension.sub!(/\A\.?(?=.)/, ".") # Ensure extension begins with dot.
38
38
  end
39
39
 
40
40
  # Cast 'delay' argument to a Float.
@@ -64,12 +64,12 @@ opt_parser = cli_options(options) do
64
64
  on("-v", "--[no-]verbose", "Run verbosely", "verbose")
65
65
 
66
66
  separator ""
67
- separator "Common @options:"
67
+ separator "Common options:"
68
68
 
69
- # No argument, shows at tail. This will print an @options summary.
69
+ # No argument, shows at tail. This will print an options summary.
70
70
  # Try it and see!
71
71
  on_tail("-h", "--help", "Show this message") do
72
- puts opts
72
+ puts options
73
73
  exit
74
74
  end
75
75
 
@@ -82,4 +82,6 @@ end
82
82
 
83
83
  opt_parser.parse!(ARGV)
84
84
  options = opt_parser.options
85
+ p options
86
+ p ARGV
85
87
 
@@ -1,3 +1,3 @@
1
1
  module DryOptionParser
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -10,9 +10,9 @@ module DryOptionParser
10
10
  class DryOptionParser < SimpleDelegator
11
11
 
12
12
  def initialize(options={},&blk)
13
+ @options = options
13
14
  super(OptionParser.new)
14
15
  instance_eval &blk
15
- @options = options
16
16
  end
17
17
 
18
18
  def assign(*args)
@@ -22,24 +22,24 @@ describe "DryOptionParser--the long OptionParser example" do
22
22
  codes = %w[iso-2022-jp shift_jis euc-jp utf8 binary]
23
23
  code_aliases = { "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
24
24
 
25
- self.banner = "Usage: example.rb [@options]"
25
+ self.banner = "Usage: example.rb [options]"
26
26
 
27
27
  separator ""
28
- separator "Specific @options:"
28
+ separator "Specific options:"
29
29
 
30
30
  # Mandatory argument.
31
- assign("library", "-r", "--require LIBRARY",
31
+ on( "-r", "--require LIBRARY",
32
32
  "Require the LIBRARY before executing your script") do |lib|
33
- @options.library << lib
33
+ options.library << lib
34
34
  end
35
35
 
36
36
  # Optional argument; multi-line description.
37
37
  on("-i", "--inplace [EXTENSION]",
38
38
  "Edit ARGV files in place",
39
39
  " (make backup if EXTENSION supplied)") do |ext|
40
- @options.inplace = true
41
- @options.extension = ext || ''
42
- @options.extension.sub!(/\A\.?(?=.)/, ".") # Ensure extension begins with dot.
40
+ options.inplace = true
41
+ options.extension = ext || ''
42
+ options.extension.sub!(/\A\.?(?=.)/, ".") # Ensure extension begins with dot.
43
43
  end
44
44
 
45
45
  # Cast 'delay' argument to a Float.
@@ -69,9 +69,9 @@ describe "DryOptionParser--the long OptionParser example" do
69
69
  on("-v", "--[no-]verbose", "Run verbosely", "verbose")
70
70
 
71
71
  separator ""
72
- separator "Common @options:"
72
+ separator "Common options:"
73
73
 
74
- # No argument, shows at tail. This will print an @options summary.
74
+ # No argument, shows at tail. This will print an options summary.
75
75
  # Try it and see!
76
76
  on_tail("-h", "--help", "Show this message") do
77
77
  puts opts
@@ -100,6 +100,8 @@ describe "DryOptionParser--the long OptionParser example" do
100
100
 
101
101
  it "-r something should add library" do
102
102
  subject.parse!(%w[-r foo])
103
+ library = subject.options[:library]
104
+ expect(library).to be_an(Array)
103
105
  expect(subject.options[:library]).to include("foo")
104
106
  end
105
107
  it "--delay 7 should assign a delay of 7.0" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry_option_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Petr Skocik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-28 00:00:00.000000000 Z
11
+ date: 2015-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler