args_parser 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9cca7b26e2263717697175dbe416ce72c78e5049
4
+ data.tar.gz: a42f0ea6b99d10f7539b57894951a41eb588d0a3
5
+ SHA512:
6
+ metadata.gz: 4939cfd55947b1090921bd2e65bb99c8726184f8a309dfe0ae500d113253f774c319958ad96b1b80a92801bae5ecd4738425095de14b9f8e13601dbba238c5d0
7
+ data.tar.gz: 549e68fcd2bffa8d75753c4a1ac8c06f9231d7e3fdb957c0bdc5332b7d96aa1855c027501af13ee79c855c12ff543b0f6df8430203a1866b30346b6111cd518e
data/Gemfile CHANGED
@@ -2,4 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in args_parser.gemspec
4
4
  gemspec
5
- gem 'minitest'
@@ -1,3 +1,7 @@
1
+ === 0.1.5 2013-06-08
2
+
3
+ * bugfix Parser#has_param?
4
+
1
5
  === 0.1.4 2013-01-26
2
6
 
3
7
  * run lambda in default value
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Sho Hashimoto
1
+ Copyright (c) 2012-2013 Sho Hashimoto
2
2
 
3
3
  MIT License
4
4
 
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -2,7 +2,7 @@ args_parser
2
2
  ===========
3
3
 
4
4
  * Parse ARGV from command line with DSL.
5
- * http://shokai.github.com/args_parser
5
+ * http://shokai.github.io/args_parser
6
6
 
7
7
 
8
8
  Requirements
@@ -29,7 +29,7 @@ parse ARGV
29
29
  require 'rubygems'
30
30
  require 'args_parser'
31
31
 
32
- parser = ArgsParser.parse ARGV do
32
+ args = ArgsParser.parse ARGV do
33
33
  arg :url, 'URL', :alias => :u
34
34
  arg :output, 'output file', :alias => :o, :default => 'out.html'
35
35
  arg :verbose, 'verbose mode'
@@ -44,17 +44,17 @@ parser = ArgsParser.parse ARGV do
44
44
  end
45
45
  end
46
46
 
47
- if parser.has_option? :help or !parser.has_param?(:url, :output)
48
- STDERR.puts parser.help
47
+ if args.has_option? :help or !args.has_param?(:url, :output)
48
+ STDERR.puts args.help
49
49
  exit 1
50
50
  end
51
51
 
52
52
  require 'open-uri'
53
- puts 'download..' if parser[:verbose]
54
- open(parser[:output], 'w+') do |f|
55
- f.write open(parser[:url]).read
53
+ puts 'download..' if args[:verbose]
54
+ open(args[:output], 'w+') do |f|
55
+ f.write open(args[:url]).read
56
56
  end
57
- puts "saved! => #{parser[:output]}"
57
+ puts "saved! => #{args[:output]}"
58
58
  ```
59
59
 
60
60
  equal style
@@ -63,7 +63,7 @@ equal style
63
63
 
64
64
  parse equal style ARGV
65
65
  ```ruby
66
- parser = ArgsParser.parse ARGV, :style => :equal do
66
+ args = ArgsArgs.parse ARGV, :style => :equal do
67
67
  ```
68
68
 
69
69
  see more samples https://github.com/shokai/args_parser/tree/master/samples
@@ -15,4 +15,9 @@ Gem::Specification.new do |gem|
15
15
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
16
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
17
  gem.require_paths = ["lib"]
18
+
19
+ gem.add_development_dependency "rake"
20
+ gem.add_development_dependency "bundler", "~> 1.3"
21
+ gem.add_development_dependency 'minitest'
22
+ gem.add_development_dependency 'json'
18
23
  end
@@ -138,7 +138,7 @@ module ArgsParser
138
138
  def has_param?(*param_)
139
139
  !(param_.flatten.map{|i|
140
140
  v = self[i]
141
- (v and [String, Fixnum, Float].include? v.class) ? true : false
141
+ (v != nil and v != true) ? true : false
142
142
  }.include? false)
143
143
  end
144
144
 
@@ -1,3 +1,3 @@
1
1
  module ArgsParser
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
@@ -5,7 +5,7 @@ $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
5
5
  require 'rubygems'
6
6
  require 'args_parser'
7
7
 
8
- parser = ArgsParser.parse ARGV do
8
+ args = ArgsParser.parse ARGV do
9
9
  arg :url, 'URL', :alias => :u
10
10
  arg :output, 'output file', :alias => :o, :default => 'out.html'
11
11
  arg :verbose, 'verbose mode'
@@ -21,22 +21,22 @@ parser = ArgsParser.parse ARGV do
21
21
  end
22
22
  end
23
23
 
24
- if parser.has_option? :help or !parser.has_param?(:url, :output)
24
+ if args.has_option? :help or !args.has_param?(:url, :output)
25
25
  STDERR.puts "Download WebPage\n=="
26
- STDERR.puts parser.help
26
+ STDERR.puts args.help
27
27
  STDERR.puts "e.g. ruby #{$0} -url http://example.com -o out.html"
28
28
  exit 1
29
29
  end
30
30
 
31
- p parser
31
+ p args
32
32
 
33
33
  require 'open-uri'
34
34
 
35
- puts 'download..' if parser[:verbose]
36
- data = open(parser[:url]).read
37
- puts data if parser[:verbose]
35
+ puts 'download..' if args[:verbose]
36
+ data = open(args[:url]).read
37
+ puts data if args[:verbose]
38
38
 
39
- open(parser[:output], 'w+') do |f|
39
+ open(args[:output], 'w+') do |f|
40
40
  f.write data
41
41
  end
42
- puts "saved! => #{parser[:output]}"
42
+ puts "saved! => #{args[:output]}"
@@ -8,7 +8,7 @@ require 'args_parser'
8
8
  gem 'twitter', '< 4.0.0', '>= 3.7.0'
9
9
  require 'twitter'
10
10
 
11
- parser = ArgsParser.parse ARGV, :style => :equal do
11
+ args = ArgsParser.parse ARGV, :style => :equal do
12
12
  arg :user, 'user', :alias => :u
13
13
  arg :favorite, 'show favorites', :alias => :fav
14
14
  arg :retweet, 'show retweets', :alias => :rt
@@ -23,30 +23,30 @@ parser = ArgsParser.parse ARGV, :style => :equal do
23
23
  end
24
24
  end
25
25
 
26
- if parser.has_option? :help or !parser.has_param? :user
26
+ if args.has_option? :help or !args.has_param? :user
27
27
  STDERR.puts "Twitter Timeline\n=="
28
- STDERR.puts parser.help
28
+ STDERR.puts args.help
29
29
  STDERR.puts "e.g. ruby #{$0} --user=ymrl"
30
30
  STDERR.puts "e.g. ruby #{$0} --user=ymrl --fav"
31
31
  STDERR.puts "e.g. ruby #{$0} --user=ymrl --fav --rt"
32
32
  exit 1
33
33
  end
34
34
 
35
- p parser
35
+ p args
36
36
 
37
37
  Twitter::configure do
38
38
  end
39
39
 
40
40
  data = []
41
- Twitter::user_timeline(parser[:user]).each do |i|
41
+ Twitter::user_timeline(args[:user]).each do |i|
42
42
  data.push(:id => i.id,
43
43
  :name => i.user.screen_name,
44
44
  :text => i.text,
45
45
  :date => i.created_at)
46
46
  end
47
47
 
48
- if parser.has_option? :favorite
49
- Twitter::favorites(parser[:user]).each do |i|
48
+ if args.has_option? :favorite
49
+ Twitter::favorites(args[:user]).each do |i|
50
50
  data.push(:id => i.id,
51
51
  :name => i.user.screen_name,
52
52
  :text => i.text,
@@ -54,8 +54,8 @@ if parser.has_option? :favorite
54
54
  end
55
55
  end
56
56
 
57
- if parser.has_option? :retweet
58
- Twitter::retweeted_by_user(parser[:user]).each do |i|
57
+ if args.has_option? :retweet
58
+ Twitter::retweeted_by_user(args[:user]).each do |i|
59
59
  data.push(:id => i.id,
60
60
  :name => i.user.screen_name,
61
61
  :text => i.text,
@@ -1,6 +1,6 @@
1
1
  require File.expand_path 'test_helper', File.dirname(__FILE__)
2
2
 
3
- class TestArgsParser < MiniTest::Unit::TestCase
3
+ class TestArgsParser < MiniTest::Test
4
4
  def setup
5
5
  @argv = 'test --input http://shokai.org -a --o ./out -h --depth 030 foo bar --pi 3.14 --n ShoKaI'.split(/\s+/)
6
6
  @parser = ArgsParser.parse @argv do
@@ -1,6 +1,6 @@
1
1
  require File.expand_path 'test_helper', File.dirname(__FILE__)
2
2
 
3
- class TestArgsParserStyleEqual < MiniTest::Unit::TestCase
3
+ class TestArgsParserStyleEqual < MiniTest::Test
4
4
  def setup
5
5
  @argv = 'test --input=http://shokai.org --a --o=./out -h --depth=-030 foo bar --pi=-3.140 --n=ShoKaI'.split(/\s+/)
6
6
  @parser = ArgsParser.parse @argv, :style => :equal do
@@ -1,6 +1,6 @@
1
1
  require File.expand_path 'test_helper', File.dirname(__FILE__)
2
2
 
3
- class TestArgsParserDefault < MiniTest::Unit::TestCase
3
+ class TestArgsParserDefault < MiniTest::Test
4
4
  def setup
5
5
  @argv = ['--age', '40']
6
6
  @parser = ArgsParser.parse @argv do
@@ -1,14 +1,20 @@
1
1
  require File.expand_path 'test_helper', File.dirname(__FILE__)
2
+ require 'json'
2
3
 
3
- class TestArgsParserFilter < MiniTest::Unit::TestCase
4
+ class TestArgsParserFilter < MiniTest::Test
4
5
  def setup
5
- @argv = ['--count', '35']
6
+ @argv = ['--count', '35', '--data', '["say","hello"]']
6
7
  @@err = nil
7
8
  @@name = nil
8
9
  @@value = nil
9
10
  @parser = ArgsParser.parse @argv do
11
+ arg :data, 'json data'
10
12
  arg :count, 'number'
11
13
 
14
+ filter :data do |v|
15
+ JSON.parse v
16
+ end
17
+
12
18
  filter :count do |v|
13
19
  raise NoMethodError, 'error!!'
14
20
  end
@@ -22,8 +28,10 @@ class TestArgsParserFilter < MiniTest::Unit::TestCase
22
28
  end
23
29
 
24
30
  def test_filter_error
25
- assert @@name == :count
26
- assert @@value == '35'
27
- assert @@err.class == NoMethodError
31
+ assert @parser.has_param? :data
32
+ assert @parser.has_param? :count
33
+ assert_equal @@name, :count
34
+ assert_equal @@value, '35'
35
+ assert_equal @@err.class, NoMethodError
28
36
  end
29
37
  end
@@ -1,6 +1,6 @@
1
1
  require File.expand_path 'test_helper', File.dirname(__FILE__)
2
2
 
3
- class TestArgsParserValidator < MiniTest::Unit::TestCase
3
+ class TestArgsParserValidator < MiniTest::Test
4
4
  def setup
5
5
  @argv = ['--url', 'hptt://shokai.org']
6
6
  @@err = nil
@@ -1,6 +1,6 @@
1
1
  require File.expand_path 'test_helper', File.dirname(__FILE__)
2
2
 
3
- class TestVersion < MiniTest::Unit::TestCase
3
+ class TestVersion < MiniTest::Test
4
4
  def test_version
5
5
  assert ArgsParser::VERSION > '0.0.0'
6
6
  end
metadata CHANGED
@@ -1,16 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: args_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
5
- prerelease:
4
+ version: 0.1.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Sho Hashimoto
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-26 00:00:00.000000000 Z
13
- dependencies: []
11
+ date: 2013-06-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
14
69
  description: Parse ARGV from command line with DSL.
15
70
  email:
16
71
  - hashimoto@shokai.org
@@ -45,27 +100,26 @@ files:
45
100
  - test/test_version.rb
46
101
  homepage: http://shokai.github.com/args_parser
47
102
  licenses: []
103
+ metadata: {}
48
104
  post_install_message:
49
105
  rdoc_options: []
50
106
  require_paths:
51
107
  - lib
52
108
  required_ruby_version: !ruby/object:Gem::Requirement
53
- none: false
54
109
  requirements:
55
- - - ! '>='
110
+ - - '>='
56
111
  - !ruby/object:Gem::Version
57
112
  version: '0'
58
113
  required_rubygems_version: !ruby/object:Gem::Requirement
59
- none: false
60
114
  requirements:
61
- - - ! '>='
115
+ - - '>='
62
116
  - !ruby/object:Gem::Version
63
117
  version: '0'
64
118
  requirements: []
65
119
  rubyforge_project:
66
- rubygems_version: 1.8.24
120
+ rubygems_version: 2.0.3
67
121
  signing_key:
68
- specification_version: 3
122
+ specification_version: 4
69
123
  summary: Parse ARGV from command line with DSL.
70
124
  test_files:
71
125
  - test/test_args_parser.rb
@@ -75,3 +129,4 @@ test_files:
75
129
  - test/test_helper.rb
76
130
  - test/test_validator.rb
77
131
  - test/test_version.rb
132
+ has_rdoc: