gli 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +42 -12
  2. data/lib/gli.rb +13 -1
  3. data/lib/gli_version.rb +1 -1
  4. metadata +17 -5
@@ -1,7 +1,7 @@
1
1
  = Git-Like Interface Command Line Parser
2
2
 
3
3
  Author:: Dave Copeland (mailto:davetron5000 at g mail dot com)
4
- Copyright:: Copyright (c) 2009 by Dave Copeland
4
+ Copyright:: Copyright (c) 2010 by Dave Copeland
5
5
  License:: Distributes under the Apache License, see LICENSE.txt in the source distro
6
6
 
7
7
  This is a DSL you can use to create a command line interface like git, gem or svn, in that the first argument is a command, and there are global and command specific flags.
@@ -24,6 +24,15 @@ This will create a basic scaffold project in <tt>./my_proj</tt> with:
24
24
  * a README shell
25
25
  * Rakefile that can generate RDoc, package your Gem and run tests
26
26
 
27
+ == Supported Platforms
28
+
29
+ Known to work on
30
+
31
+ * 1.8.7
32
+ * 1.9.2
33
+
34
+ Though likely works on various other versions
35
+
27
36
  === Example
28
37
 
29
38
  This example demonstrates most of the features of GLI.
@@ -48,18 +57,19 @@ the file will be located relative to the current user's home directory (which is
48
57
 
49
58
  config_file '.glirc'
50
59
 
51
- the configuration file
52
60
  This describes a command line switch "-n" that is global to all commands and specified before
53
61
  the command name on the command line.
54
62
 
55
63
  desc 'Dry run; don\'t change the disk'
56
64
  switch :n
57
65
 
58
- The following describes a command line flag that is global and has a default value of '<tt>.</tt>'. It also
59
- specifies a short description of its argument. This is used to print command line help. Note that we
66
+ The following describes a command line flag that is global and has a default value of '<tt>.</tt>' (in GLI parlance,
67
+ a "flag" is a command line switch that takes an option). It also
68
+ specifies a short and long description of its argument. This is used to print command line help and to generate
69
+ rdoc documentation. Note that we
60
70
  have specified two different aliases for this flag. <tt>-r</tt> (because it is listed first) is the default
61
71
  one and <tt>--root</tt> (note two-dash syntax) is also supported. This means that <tt>-r some_dir</tt> and <tt>--root=some_dir</tt> mean
62
- the same thing to the application.
72
+ the same thing to the application, but that your code should look for <tt>:r</tt>.
63
73
 
64
74
  desc 'Root dir in which to create project'
65
75
  long_desc 'This is the location where your project ill be created. A subdirectory named for your project will be created here, and THAT directory will contain the generated files'
@@ -67,7 +77,7 @@ the same thing to the application.
67
77
  arg_name 'root_dir'
68
78
  flag [:r,:root]
69
79
 
70
- Here we specify a command. Inside the block we can use the same sorts of things as we did above to define flags
80
+ Next, we specify a command. Inside the block we can use the same sorts of things as we did above to define flags
71
81
  and switches specific to the command. These must come after the command name. Also note that we use <tt>arg_name</tt>
72
82
  here to describe the arguments this command accepts.
73
83
 
@@ -81,15 +91,23 @@ here to describe the arguments this command accepts.
81
91
  c.desc 'Overwrite/ignore existing files and directories'
82
92
  c.switch [:force]
83
93
 
84
- Here we specify the actual actions to take when the command is executed. We define a block that
85
- will be given the global options (as a Hash), the command-specific options (as a hash) and the command
86
- line arguments
94
+ Next, while we are still inside the <tt>command</tt> block,
95
+ we specify the actual code to execute when the command is chosen by the user. We define a block that
96
+ will be given the global options (as a Hash), the command-specific options (as a Hash) and the command
97
+ line arguments. The hashes keys are symbols based upon the switches and flags. For a switch or
98
+ flag named "-r", we would use <tt>:r</tt>.
87
99
 
88
100
  c.action do |global_options,options,args|
89
101
  if args.length < 1
90
102
  raise 'You must specify the name of your project'
91
103
  end
92
- Scaffold.create_scaffold(g[:r],!o[:notest],o[:e],args[0],args[1..-1],o[:force],g[:n])
104
+ Scaffold.create_scaffold(global_options[:r],
105
+ !options[:notest],
106
+ options[:e],
107
+ args[0],
108
+ args[1..-1],
109
+ ooptions[:force],
110
+ global_options[:n])
93
111
  end
94
112
  end
95
113
 
@@ -98,7 +116,8 @@ You can also specify some global code to run before, after and on errors:
98
116
  pre do |global_options,command,options,args|
99
117
  puts "After parsing, but before #{command.name} is run"
100
118
  return true
101
- # return false if we want to skip command execution for some reason
119
+ # return false if we want to skip command execution for some reason,
120
+ # such as some global precondition not having been met
102
121
  end
103
122
 
104
123
  post do |global_options,command,options,args|
@@ -123,7 +142,8 @@ What this gives you:
123
142
  * Error handling when flags do not receive arguments or unknown flags or switches are given
124
143
  * Error handling when an unknown command is specified
125
144
  * Default values for flags if they are not specified by the user (switches all default to false)
126
- * An easy way to allow location-specific defaults for options via a config file for your app
145
+ * An easy way to allow user or site-specific defaults for options via a config file for your app
146
+ * Nice RDoc describing how to use your application (you can see an example in the rdoc version of this file for the <tt>gli</tt> command)
127
147
 
128
148
  What this doesn't give you:
129
149
 
@@ -170,6 +190,16 @@ command of your application is created, to allow the user edit the config file
170
190
  This allows you to design your application to have it's behavior _entirely_ affected by command line options, with sensible
171
191
  defaults stored in a configuration file.
172
192
 
193
+ == Generating RDoc
194
+
195
+ All gli-based applications include a "hidden" command named <tt>rdoc</tt>. When you execute this command, a file called <tt>yourapp.rdoc</tt>
196
+ is created in the current directory. This contains a rdoc-formatted helpfile for your command line application. This can be useful
197
+ in packaging your application to share with others. This is also the only place in which the <tt>long_desc</tt> values are currently
198
+ used.
199
+
200
+ If your application has a <tt>README.rdoc</tt> already, you can simply add <tt>:include:yourapp.rdoc</tt> to the bottom and it will
201
+ be included when you generate and publish your rdoc (note that it will *not* show up on github).
202
+
173
203
  == Reference
174
204
 
175
205
 
data/lib/gli.rb CHANGED
@@ -40,6 +40,7 @@ module GLI
40
40
 
41
41
  # describe the argument name of the next flag
42
42
  def arg_name(name); @@next_arg_name = name; end
43
+
43
44
  # set the default value of the next flag
44
45
  def default_value(val); @@next_default_value = val; end
45
46
 
@@ -255,7 +256,18 @@ module GLI
255
256
 
256
257
  flag_hash.each do |name,flag|
257
258
  value = flag.get_value!(try_me)
258
- options[name] = value if value
259
+ # So, there's a case where the first time we request the value for a flag,
260
+ # we get the default and not the user-provided value. The next time we request
261
+ # it, we want to override it with the real value.
262
+ # HOWEVER, sometimes this happens in reverse, so we want to err on taking the
263
+ # user-provided, non-default value where possible.
264
+ if value
265
+ if options[name]
266
+ options[name] = value if options[name] == flag.default_value
267
+ else
268
+ options[name] = value
269
+ end
270
+ end
259
271
  end
260
272
 
261
273
  if try_me.empty?
@@ -1,3 +1,3 @@
1
1
  module GLI
2
- VERSION = '1.1.1'
2
+ VERSION = '1.1.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 1
9
+ - 2
10
+ version: 1.1.2
5
11
  platform: ruby
6
12
  authors:
7
13
  - David Copeland
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-06-12 00:00:00 -04:00
18
+ date: 2010-10-19 00:00:00 -04:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -52,21 +58,27 @@ require_paths:
52
58
  - lib
53
59
  - lib
54
60
  required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
55
62
  requirements:
56
63
  - - ">="
57
64
  - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
58
68
  version: "0"
59
- version:
60
69
  required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
61
71
  requirements:
62
72
  - - ">="
63
73
  - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
64
77
  version: "0"
65
- version:
66
78
  requirements: []
67
79
 
68
80
  rubyforge_project: gli
69
- rubygems_version: 1.3.5
81
+ rubygems_version: 1.3.7
70
82
  signing_key:
71
83
  specification_version: 3
72
84
  summary: A Git Like Interface for building command line apps