ArgsParser 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.0.10 2010-12-1
2
+
3
+ * fix help string of long argument
4
+
1
5
  === 0.0.8 2010-06-26
2
6
 
3
7
  * fix my name
@@ -74,26 +74,31 @@ class Parser
74
74
  end
75
75
 
76
76
  def help
77
- binds_reversed = Hash.new
78
- most_longname_size = 0
79
- @binds.keys.each{|key|
80
- value = @binds[key]
81
- binds_reversed[value] = key
82
- if most_longname_size < len = key.to_s.size + value.to_s.size
83
- most_longname_size = len
84
- end
77
+ lines = Hash.new
78
+ @comments.each{|k,v|
79
+ lines[k] = {:comment => v}
85
80
  }
86
81
 
87
- s = "options:\n"
88
- @comments.keys.sort{|a,b| a.to_s <=> b.to_s }.each{|name|
89
- comment = @comments[name]
90
- if shortname = binds_reversed[name]
91
- s += " -#{name} (-#{shortname})" +
92
- " "*(most_longname_size-name.to_s.size-shortname.to_s.size+2) + "#{comment}\n"
93
- else
94
- s += " -#{name}" + " "*(most_longname_size-name.to_s.size+6) + "#{comment}\n"
95
- end
82
+ @binds.each{|k,v|
83
+ lines[v][:binds] = k
84
+ }
85
+
86
+ most_long = 0
87
+ lines.each{|k,v|
88
+ name = " -#{k}"
89
+ name += " (-#{v[:binds]})" if v[:binds]
90
+ most_long = name.size if most_long < name.size
91
+ }
92
+
93
+ s = ""
94
+ lines.each{|k,v|
95
+ name = " -#{k}"
96
+ name += " (-#{v[:binds]})" if v[:binds]
97
+ line = name.ljust(most_long+2)
98
+ line += v[:comment]
99
+ s += line+"\n"
96
100
  }
101
+ s = "options:\n" + s
97
102
  return s
98
103
  end
99
104
 
data/lib/ArgsParser.rb CHANGED
@@ -6,7 +6,7 @@ directory = File.expand_path(File.dirname(__FILE__))
6
6
  require File.join(directory, 'ArgsParser', 'Parser')
7
7
 
8
8
  module ArgsParser
9
- VERSION = '0.0.9'
9
+ VERSION = '0.0.10'
10
10
 
11
11
  def ArgsParser.parser
12
12
  Parser.new
data/spec/parser_spec.rb CHANGED
@@ -22,12 +22,17 @@ describe "test of parsing params" do
22
22
  '-yscale', '240',
23
23
  '-debug']
24
24
  @parser = ArgsParser.parser
25
- @parser.comment(:debug, "debug mode")
26
- @parser.bind(:xscale, :x, "width")
27
- @parser.bind(:yscale, :y, "height")
25
+ @parser.comment(:debug, 'debug mode')
26
+ @parser.bind(:xscale, :x, 'width')
27
+ @parser.bind(:yscale, :y, 'height')
28
+ @parser.comment(:test_for_error_cauased_by_long_argument, 'long arguent')
28
29
  @first, @params = @parser.parse(@argv)
29
30
  end
30
31
 
32
+ it 'should return help as string' do
33
+ @parser.help.class.should == String
34
+ end
35
+
31
36
  it "has not first-arg" do
32
37
  @first.should == nil
33
38
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ArgsParser
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 9
10
- version: 0.0.9
9
+ - 10
10
+ version: 0.0.10
11
11
  platform: ruby
12
12
  authors:
13
13
  - shokai
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-05 00:00:00 +09:00
18
+ date: 2010-12-01 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -42,12 +42,12 @@ dependencies:
42
42
  requirements:
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- hash: 21
45
+ hash: 19
46
46
  segments:
47
47
  - 2
48
48
  - 6
49
- - 1
50
- version: 2.6.1
49
+ - 2
50
+ version: 2.6.2
51
51
  type: :development
52
52
  version_requirements: *id002
53
53
  description: "* Parse args from command line."