gli 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,7 @@
1
1
  == Changelog
2
+ === 1.2.1 - 11/26/2010
3
+
4
+ * Changed default data structure of options *back* to a <tt>Hash</tt>. If you want to use the <tt>OpenStruct</tt> subclass <tt>Options</tt>, simply put <tt>use_openstruct true</tt> in your command line definition.
2
5
 
3
6
  === 1.2.0 - 11/26/2010
4
7
 
@@ -26,6 +26,7 @@ This will create a basic scaffold project in <tt>./my_proj</tt> with:
26
26
  * a gemspec shell
27
27
  * a README shell
28
28
  * Rakefile that can generate RDoc, package your Gem and run tests
29
+ * A <tt>Gemfile</tt> suitable for use with Bundler to manage development-time dependencies
29
30
 
30
31
  == Supported Platforms
31
32
 
@@ -211,8 +212,6 @@ be included when you generate and publish your rdoc (note that it will *not* sho
211
212
 
212
213
  == Bash Completion
213
214
 
214
- <i>Not available in current release yet</i>
215
-
216
215
  The +help+ command takes an optional switch, +-c+, that will list all the commands (including aliases) in sorted order suitable for use in a bash completion script. When +-c+ is specified, the argument can be a partial command, and +help+ will only list the commands matching. Put this in your +.bashrc+:
217
216
 
218
217
  complete -F get_myapp_targets myapp
data/lib/gli.rb CHANGED
@@ -20,6 +20,8 @@ module GLI
20
20
  @@pre_block = nil
21
21
  @@error_block = nil
22
22
  @@config_file = nil
23
+ @@use_openstruct = false
24
+ @@version = nil
23
25
 
24
26
  # Reset the GLI module internal data structures; mostly for testing
25
27
  def reset
@@ -28,6 +30,7 @@ module GLI
28
30
  commands.clear
29
31
  @@version = nil
30
32
  @@config_file = nil
33
+ @@use_openstruct = false
31
34
  clear_nexts
32
35
  end
33
36
 
@@ -113,6 +116,14 @@ module GLI
113
116
  @@version = version
114
117
  end
115
118
 
119
+ # Call this with "true" will cause the <tt>global_options</tt> and
120
+ # <tt>options</tt> passed to your code to be wrapped in
121
+ # GLI::Option, which is a subclass of OpenStruct that adds
122
+ # <tt>[]</tt> and <tt>[]=</tt> methods.
123
+ def use_openstruct(use_openstruct)
124
+ @@use_openstruct = use_openstruct
125
+ end
126
+
116
127
  # Runs whatever command is needed based on the arguments.
117
128
  def run(args)
118
129
  rdoc = RDocCommand.new
@@ -123,6 +134,8 @@ module GLI
123
134
  global_options,command,options,arguments = parse_options(args,config)
124
135
  copy_options_to_aliased_versions(global_options,command,options)
125
136
  proceed = true
137
+ global_options = convert_to_option?(global_options)
138
+ options = convert_to_option?(options)
126
139
  proceed = @@pre_block.call(global_options,command,options,arguments) if @@pre_block
127
140
  if proceed
128
141
  command = commands[:help] if !command
@@ -139,6 +152,13 @@ module GLI
139
152
  end
140
153
  end
141
154
 
155
+ # Possibly returns a copy of the passed-in Hash as an instance of GLI::Option.
156
+ # By default, it will *not*, however by putting <tt>use_openstruct true</tt>
157
+ # in your CLI definition, it will
158
+ def convert_to_option?(options)
159
+ @@use_openstruct ? Options.new(options) : options
160
+ end
161
+
142
162
  # Copies all options in both global_options and options to keys for the aliases of those flags.
143
163
  # For example, if a flag works with either -f or --flag, this will copy the value from [:f] to [:flag]
144
164
  # to allow the user to access the options by any alias
@@ -197,7 +217,7 @@ module GLI
197
217
  else
198
218
  command_configs = config.delete(GLI::InitConfig::COMMANDS_KEY) if !config.nil?
199
219
  end
200
- global_options,command,options,arguments = parse_options_helper(args.clone,config,nil,Options.new,Array.new,command_configs)
220
+ global_options,command,options,arguments = parse_options_helper(args.clone,config,nil,Hash.new,Array.new,command_configs)
201
221
  flags.each { |name,flag| global_options[name] = flag.default_value if !global_options[name] }
202
222
  command.flags.each { |name,flag| options[name] = flag.default_value if !options[name] }
203
223
  return [global_options,command,options,arguments]
@@ -1,14 +1,16 @@
1
1
  require 'ostruct'
2
2
 
3
- class Options < OpenStruct
3
+ module GLI
4
+ class Options < OpenStruct
4
5
 
5
- def[](k)
6
- @table[k.to_sym]
7
- end
6
+ def[](k)
7
+ @table[k.to_sym]
8
+ end
8
9
 
9
- def[]=(k, v)
10
- @table[k.to_sym] = v
11
- end
10
+ def[]=(k, v)
11
+ @table[k.to_sym] = v
12
+ end
12
13
 
14
+ end
13
15
  end
14
16
 
@@ -1,3 +1,3 @@
1
1
  module GLI
2
- VERSION = '1.2.0'
2
+ VERSION = '1.2.1'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gli
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 0
10
- version: 1.2.0
9
+ - 1
10
+ version: 1.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Copeland