config_parser 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ == 0.5.4 / 2011-07-11
2
+
3
+ Misc cleanup to the README and project structure. Also:
4
+
5
+ * guess no hint for empty array
6
+
1
7
  == 0.5.3 / 2010-12-04
2
8
 
3
9
  * altered targname formatting for list to use an elipsis rather than brackets
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010, Simon Chiang
1
+ Copyright (c) 2010-2011, Simon Chiang
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person
4
4
  obtaining a copy of this software and associated documentation
data/README.rdoc ADDED
@@ -0,0 +1,92 @@
1
+ = ConfigParser
2
+
3
+ Parse command-line options into a configuration hash.
4
+
5
+ == Description
6
+
7
+ ConfigParser is an analogue of
8
+ {OptionParser}[http://www.ruby-doc.org/core/classes/OptionParser.html] that
9
+ formalizes the pattern of setting parsed options into a hash. ConfigParser
10
+ uses a similar, simplified declaration syntax and provides an API that
11
+ integrates well with libraries like
12
+ {Configurable}[http://github.com/thinkerbot/configurable].
13
+
14
+ == Usage
15
+
16
+ Define options and their default values using +add+:
17
+
18
+ parser = ConfigParser.new
19
+ parser.add :option, 'default' # regular option with a default value
20
+ parser.add :switch, true # true makes a --[no-]switch
21
+ parser.add :flag, false # false as a default makes a --flag
22
+ parser.add :list, [] # an array makes a list-style option
23
+
24
+ parser.parse 'a b --flag --list x --list y,z c'
25
+ # => ['a', 'b', 'c']
26
+
27
+ parser.config
28
+ # => {
29
+ # :option => 'default',
30
+ # :switch => true,
31
+ # :flag => true,
32
+ # :list => ['x', 'y', 'z']
33
+ # }
34
+
35
+ The OptionParser +on+ syntax may also be used, if desired (most syntax
36
+ variations will work). Use the parser as if it were the config hash:
37
+
38
+ parser = ConfigParser.new
39
+ parser.on '--option OPTION', 'a standard option' do |value|
40
+ parser[:option] = value
41
+ end
42
+
43
+ parser.on '--[no-]switch', 'a switch' do |value|
44
+ parser[:switch] = value
45
+ end
46
+
47
+ parser.on '--flag', 'a flag' do
48
+ parser[:flag] = true
49
+ end
50
+
51
+ parser.parse 'a b --flag --switch --option value c'
52
+ # => ['a', 'b', 'c']
53
+
54
+ parser.config
55
+ # => {
56
+ # :option => 'value',
57
+ # :switch => true,
58
+ # :flag => true
59
+ # }
60
+
61
+ Added options may be further defined using arguments just like +on+ or with an
62
+ attributes hash. Notably, the key for the config does not have to correspond
63
+ to the option (although by default it does). As you may expect a block can be
64
+ given to process values before they are set as configs.
65
+
66
+ parser = ConfigParser.new
67
+
68
+ # use args to define the option
69
+ parser.add(:x, nil, '-o', '--one')
70
+
71
+ # use an options hash to define the option
72
+ parser.add(:y, nil, :short => 't', :long => 'two')
73
+
74
+ # use a block to process the values
75
+ parser.add(:z, nil, :long => 'three') {|value| value.upcase }
76
+
77
+ parser.parse('a b --one uno --two dos --three tres c')
78
+ # => ['a', 'b', 'c']
79
+
80
+ parser.config
81
+ # => {:x => 'uno', :y => 'dos', :z => 'TRES'}
82
+
83
+ == Installation
84
+
85
+ ConfigParser is available as a gem[http://rubygems.org/gems/config_parser].
86
+
87
+ % gem install config_parser
88
+
89
+ == Info
90
+
91
+ Developer:: {Simon Chiang}[http://github.com/thinkerbot]
92
+ License:: {MIT-Style}[link:files/MIT-LICENSE.html]
@@ -221,7 +221,8 @@ class ConfigParser
221
221
  when true, false, nil
222
222
  nil
223
223
  when Array
224
- default.join(attrs[:delimiter] || DELIMITER)
224
+ hint = default.join(attrs[:delimiter] || DELIMITER)
225
+ hint.empty? ? nil : hint
225
226
  else
226
227
  default.to_s
227
228
  end
@@ -1,7 +1,7 @@
1
1
  class ConfigParser
2
2
  MAJOR = 0
3
3
  MINOR = 5
4
- TINY = 3
4
+ TINY = 4
5
5
 
6
6
  VERSION = "#{MAJOR}.#{MINOR}.#{TINY}"
7
7
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config_parser
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
5
- prerelease: false
4
+ hash: 3
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 3
10
- version: 0.5.3
9
+ - 4
10
+ version: 0.5.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Simon Chiang
@@ -15,28 +15,13 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-04 00:00:00 -07:00
18
+ date: 2011-07-11 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: lazydoc
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 15
30
- segments:
31
- - 1
32
- - 0
33
- version: "1.0"
34
- type: :runtime
35
- version_requirements: *id001
36
21
  - !ruby/object:Gem::Dependency
37
22
  name: bundler
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ requirement: &id001 !ruby/object:Gem::Requirement
40
25
  none: false
41
26
  requirements:
42
27
  - - ~>
@@ -47,7 +32,7 @@ dependencies:
47
32
  - 0
48
33
  version: "1.0"
49
34
  type: :development
50
- version_requirements: *id002
35
+ version_requirements: *id001
51
36
  description:
52
37
  email: simon.a.chiang@gmail.com
53
38
  executables: []
@@ -55,8 +40,8 @@ executables: []
55
40
  extensions: []
56
41
 
57
42
  extra_rdoc_files:
58
- - History
59
- - README
43
+ - History.rdoc
44
+ - README.rdoc
60
45
  - MIT-LICENSE
61
46
  files:
62
47
  - lib/config_parser.rb
@@ -66,8 +51,8 @@ files:
66
51
  - lib/config_parser/switch.rb
67
52
  - lib/config_parser/utils.rb
68
53
  - lib/config_parser/version.rb
69
- - History
70
- - README
54
+ - History.rdoc
55
+ - README.rdoc
71
56
  - MIT-LICENSE
72
57
  has_rdoc: true
73
58
  homepage: ""
@@ -76,7 +61,7 @@ licenses: []
76
61
  post_install_message:
77
62
  rdoc_options:
78
63
  - --main
79
- - README
64
+ - README.rdoc
80
65
  - -S
81
66
  - -N
82
67
  - --title
@@ -104,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
89
  requirements: []
105
90
 
106
91
  rubyforge_project: ""
107
- rubygems_version: 1.3.7
92
+ rubygems_version: 1.6.2
108
93
  signing_key:
109
94
  specification_version: 3
110
95
  summary: Parse command-line options into a configuration hash
data/README DELETED
@@ -1,95 +0,0 @@
1
- = ConfigParser
2
-
3
- Parse command-line options into a configuration hash.
4
-
5
- == Description
6
-
7
- ConfigParser is an analogue of
8
- {OptionParser}[http://www.ruby-doc.org/core/classes/OptionParser.html] that
9
- formalizes the pattern of setting parsed options into a hash. ConfigParser
10
- uses a similar, simplified declaration syntax and provides an API that
11
- integrates well with libraries like
12
- {Configurable}[http://tap.rubyforge.org/configurable].
13
-
14
- == Usage
15
-
16
- ConfigParser can be used much like OptionParser, where the parser can set
17
- values into a config hash.
18
-
19
- parser = ConfigParser.new
20
- parser.on '-s', '--long LONG', 'a standard option' do |value|
21
- parser[:long] = value
22
- end
23
-
24
- parser.on '--[no-]switch', 'a switch' do |value|
25
- parser[:switch] = value
26
- end
27
-
28
- parser.on '--flag', 'a flag' do
29
- parser[:flag] = true
30
- end
31
-
32
- parser.parse('a b --long arg --switch --flag c')
33
- # => ['a', 'b', 'c']
34
-
35
- parser.config
36
- # => {:long => 'arg', :switch => true, :flag => true}
37
-
38
- parser.to_s
39
- # => %q{
40
- # -s, --long LONG a standard option
41
- # --[no-]switch a switch
42
- # --flag a flag
43
- # }
44
-
45
- ConfigParser formalizes this pattern of setting values into a config hash as
46
- they occur, and adds the ability to specify default values.
47
-
48
- parser = ConfigParser.new
49
- parser.add :flag, false # false as a default makes a --flag
50
- parser.add :switch, true # true makes a --[no-]switch
51
- parser.add :list, [] # an array makes a list-style option
52
- parser.add :opt, 'default' # all others make an ordinary option
53
-
54
- parser.parse('a b c') # => ['a', 'b', 'c']
55
- parser.config
56
- # => {
57
- # :flag => false,
58
- # :switch => true,
59
- # :list => [],
60
- # :opt => 'default'
61
- # }
62
-
63
- args = %w{a b --flag --no-switch --list one --list two,three --opt value c}
64
- parser.parse(args) # => ['a', 'b', 'c']
65
- parser.config
66
- # => {
67
- # :flag => true,
68
- # :switch => false,
69
- # :list => ['one', 'two', 'three'],
70
- # :opt => 'value'
71
- # }
72
-
73
- Options can be defined using arguments just like on, or with an attributes
74
- hash. A block can be given to process values before they are set as configs.
75
-
76
- parser = ConfigParser.new
77
- parser.add(:x, nil, '--one', 'by args') {|value| value.upcase }
78
- parser.add(:y, nil, :long => 'two', :desc => 'by hash')
79
-
80
- parser.parse('a b --one value --two value c')
81
- # => ['a', 'b', 'c']
82
-
83
- parser.config
84
- # => {:x => 'VALUE', :y => 'value'}
85
-
86
- == Installation
87
-
88
- ConfigParser is available as a gem via {Gemcutter}[http://rubygems.org/gems/config_parser].
89
-
90
- % gem install config_parser
91
-
92
- == Info
93
-
94
- Copyright (c) 2010, Simon Chiang
95
- License:: {MIT-Style}[link:files/MIT-LICENSE.html]