optparse_plus 0.0.1 → 0.0.2

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: c10b81ae4f69b69d772aa4485b9958f025f3bc1c
4
- data.tar.gz: 57164625aa775c5c1c2cd151fd3be1b1aeacc48d
3
+ metadata.gz: fb5cd3f950ad3d9c06b4553d5b2597626a4416f7
4
+ data.tar.gz: f3cba69f07aa05c98fdd3032c7c7909f63d01780
5
5
  SHA512:
6
- metadata.gz: 73c3e461022b46a4682711eb0938c2b0851968243091017adc3c29d41e3209df0ac950efd0343b50c414bd09849ea2984025ed68502ad9e6cdf0c0015a30a220
7
- data.tar.gz: 17ac8719eb55a7d1e9303b98d025b5c3f31e81ce627bdecbc93bfe4163f46800bf469180404d8a7d93223cafe39988e0e2f46054527fd07908bfe18c84b2f432
6
+ metadata.gz: 120ed7f19379852c94720f69b56dda4ab54d3793c5cc2efd3c3c9ecd2bb94cbd53eead0ba4f1f9a9d6334a68fa0ed4d5debb6b5486766fd91b2dee2b78706887
7
+ data.tar.gz: 32137b706fa2c5a5029ff9ac1fd27542a7c0f60b605d9b8a02070417ed009a0e2d25a0eaaf3e853d29d80f2f45de760ff2468e72986a7a64d3bc0b7291ec4454
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # OptparsePlus
2
2
 
3
- OptParsePlus adds some helper methods to OptionParser, and let you define command line options more easily.
3
+ OptparsePlus adds some helper methods to OptionParser, and let you define command line options more easily.
4
4
 
5
5
  In your script, simply require 'optparse_plus' in stead of 'optparse', then the new methods of OptionParser are available for you.
6
6
 
@@ -30,6 +30,8 @@ require 'optparse_plus'
30
30
  first_value, second_value = nil, nil
31
31
 
32
32
  OptionParser.new_with_yaml do |opt|
33
+ opt.inherit_ruby_options("E") # Currently, -E and -d only are available options
34
+
33
35
  opt.on(:first_option) {|status| first_value = status }
34
36
  opt.on(:second_option) {|arg| second_value = arg }
35
37
  opt.parse!
@@ -57,7 +59,7 @@ And if you execute:
57
59
  You will see the following message:
58
60
 
59
61
  ```
60
- test_program [OPTION]
62
+ test_program.rb [OPTION]
61
63
  -E, --encoding=ex[:in] specify the default external and internal character encodings
62
64
  -f, --first First option for a test script
63
65
  -s, --second [=arg] Second option for a test script
@@ -96,6 +98,8 @@ second_option:
96
98
  YAML
97
99
 
98
100
  OptionParser.new_with_yaml(config_yaml) do |opt|
101
+ opt.inherit_ruby_options("E") # Currently, -E and -d only are available options
102
+
99
103
  opt.on(:first_option) {|status| first_value = status }
100
104
  opt.on(:second_option) {|arg| second_value = arg }
101
105
  opt.parse!
@@ -1,3 +1,3 @@
1
1
  module OptparsePlus
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/optparse_plus.rb CHANGED
@@ -8,7 +8,7 @@ module OptparsePlus
8
8
 
9
9
  module ClassMethods
10
10
  def read_after_program_end(cur_file)
11
- own_source = File.read(cur_file)
11
+ own_source = open(cur_file) {|f| f.read }
12
12
  last_token = Ripper.lex(own_source)[-1]
13
13
  return nil unless last_token[1] == :on___end__
14
14
  start = last_token[0][0]
@@ -134,7 +134,7 @@ YAML
134
134
  end
135
135
 
136
136
  def parse!
137
- @opt_plus.opt_on
137
+ @opt_plus.opt_on if @opt_plus
138
138
  super
139
139
  end
140
140
 
@@ -97,6 +97,14 @@ describe OptparsePlus do
97
97
  end
98
98
 
99
99
  context("when options are registered using OptionParser#on") do
100
+ it 'accepts normal definitions' do
101
+ parser = OptparsePlusTest.new
102
+ set_argv("--first --second=something")
103
+ parser.parse_normal_definitions_using_on
104
+ expect(parser.first_option_given?).to be_truthy
105
+ expect(parser.second_option_value).to eq("something")
106
+ end
107
+
100
108
  it 'accepts --second option with an argument' do
101
109
  parser = OptparsePlusTest.new
102
110
  set_argv("--first --second=something")
@@ -192,6 +200,15 @@ second_option:
192
200
  YAML
193
201
  end
194
202
 
203
+ describe '.new_with_yaml' do
204
+ it 'should not call File.read class method directly' do
205
+ # expect(File).to receive(:read) do
206
+ OptionParser.new_with_yaml(@config_yaml_with_banner)
207
+ # end
208
+ raise "An appropriate test should be added."
209
+ end
210
+ end
211
+
195
212
  describe '#config_to_args' do
196
213
  it 'can convert config in yaml to args of OptionParser#on' do
197
214
  opt_plus = OptionParser::OptPlus.new(@config_yaml_without_banner)
@@ -53,6 +53,19 @@ YAML
53
53
  opt.parse!
54
54
  end
55
55
  end
56
+
57
+ def parse_normal_definitions_using_on
58
+ OptionParser.new("#{File.basename($0)} [OPTION]") do |opt|
59
+ opt.on('-f', '--first',
60
+ 'First option for a test script') {|status| @first_option_given = status }
61
+ # opt.on(:first_option) {|status| @first_option_given = status }
62
+
63
+ opt.on('-s [arg]', '--second [=arg]',
64
+ 'Second option for a test script') {|arg| @second_option_value = arg }
65
+ # opt.on(:second_option) {|arg| @second_option_value = arg }
66
+ opt.parse!
67
+ end
68
+ end
56
69
  end
57
70
 
58
71
  __END__
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optparse_plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - HASHIMOTO, Naoki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-05 00:00:00.000000000 Z
11
+ date: 2016-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: "\"optparse_plus\" will let you define command line options more easily."
55
+ description: '"optparse_plus" will let you define command line options more easily.'
56
56
  email:
57
57
  - hashimoto.naoki@gmail.com
58
58
  executables: []
@@ -93,12 +93,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  requirements: []
95
95
  rubyforge_project:
96
- rubygems_version: 2.2.0
96
+ rubygems_version: 2.6.4
97
97
  signing_key:
98
98
  specification_version: 4
99
- summary: "\"optparse_plus\" adds some helper methods to OptionParser. In your script,
100
- simply require 'optparse_plus' in stead of 'optparse', then the new methods of OptionParser
101
- are available for you."
99
+ summary: '"optparse_plus" adds some helper methods to OptionParser. In your script,
100
+ simply require ''optparse_plus'' in stead of ''optparse'', then the new methods
101
+ of OptionParser are available for you.'
102
102
  test_files:
103
103
  - spec/optparse_plus_spec.rb
104
104
  - spec/spec_helper.rb