davetron5000-gli 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +5 -3
- data/bin/gli +5 -5
- data/lib/gli.rb +4 -5
- data/lib/support/scaffold.rb +35 -3
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -28,10 +28,10 @@ the command name on the command line.
|
|
28
28
|
switch :n
|
29
29
|
|
30
30
|
|
31
|
-
This
|
32
|
-
|
31
|
+
This describes a command line flag that is global and has a default value of '<tt>.</tt>'. It also
|
32
|
+
specifies a short description of its argument. This is used to print command line help. Note that we
|
33
33
|
have specified two different aliases for this flag. <tt>-r</tt> (because it is listed first) is the default
|
34
|
-
one and <tt>--root</tt> is also supported. This means that <tt>-r some_dir</tt> and <tt>--root=some_dir</tt> mean
|
34
|
+
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
|
35
35
|
the same thing to the application.
|
36
36
|
|
37
37
|
desc 'Root dir in which to create project'
|
@@ -69,6 +69,8 @@ You can also specify some global code to run before, after and on errors:
|
|
69
69
|
|
70
70
|
pre do |global_options,command,options,args|
|
71
71
|
puts "After parsing, but before #{command.name} is run"
|
72
|
+
return true
|
73
|
+
# return false if we want to skip command execution for some reason
|
72
74
|
end
|
73
75
|
|
74
76
|
post do |global_options,command,options,args|
|
data/bin/gli
CHANGED
@@ -14,7 +14,7 @@ switch :version
|
|
14
14
|
desc 'Dry run; don\'t change the disk'
|
15
15
|
switch :n
|
16
16
|
|
17
|
-
desc 'Root dir
|
17
|
+
desc 'Root dir of project'
|
18
18
|
default_value '.'
|
19
19
|
flag [:r,:root]
|
20
20
|
|
@@ -53,9 +53,9 @@ post do |global,command,options,args|
|
|
53
53
|
puts "Executed #{command.name}" if global[:v]
|
54
54
|
end
|
55
55
|
|
56
|
-
on_error do |global,command,options,args|
|
57
|
-
puts "Got an error" if global[:v]
|
58
|
-
true
|
59
|
-
end
|
56
|
+
#on_error do |global,command,options,args|
|
57
|
+
# puts "Got an error" if global[:v]
|
58
|
+
# true
|
59
|
+
#end
|
60
60
|
|
61
61
|
run(ARGV)
|
data/lib/gli.rb
CHANGED
@@ -10,7 +10,7 @@ require 'support/help.rb'
|
|
10
10
|
module GLI
|
11
11
|
extend self
|
12
12
|
|
13
|
-
VERSION = '0.1.
|
13
|
+
VERSION = '0.1.5'
|
14
14
|
|
15
15
|
@@program_name = $0.split(/\//)[-1]
|
16
16
|
@@post_block = nil
|
@@ -72,7 +72,8 @@ module GLI
|
|
72
72
|
end
|
73
73
|
|
74
74
|
# Define a block to run if an error occurs.
|
75
|
-
# The block will receive the
|
75
|
+
# The block will receive the exception that was caught.
|
76
|
+
# It should return false to avoid the built-in error handling
|
76
77
|
def on_error(&a_proc)
|
77
78
|
@@error_block = a_proc
|
78
79
|
end
|
@@ -91,9 +92,7 @@ module GLI
|
|
91
92
|
end
|
92
93
|
rescue UnknownCommandException, UnknownArgumentException, MissingArgumentException => ex
|
93
94
|
regular_error_handling = true
|
94
|
-
if @@error_block
|
95
|
-
regular_error_handling = @@error_block.call(global_options,command,options,arguments,ex)
|
96
|
-
end
|
95
|
+
regular_error_handling = @@error_block.call(ex) if @@error_block
|
97
96
|
|
98
97
|
if regular_error_handling
|
99
98
|
puts "error: #{ex}"
|
data/lib/support/scaffold.rb
CHANGED
@@ -20,10 +20,12 @@ module GLI
|
|
20
20
|
if !File.exist?(bin_file) || force
|
21
21
|
if !dry_run
|
22
22
|
File.open(bin_file,'w') do |file|
|
23
|
+
file.chmod(0755)
|
23
24
|
file.puts '#!/usr/bin/ruby'
|
24
25
|
file.puts '$: << File.expand_path(File.dirname(__FILE__) + \'/../lib\')'
|
25
26
|
file.puts '$: << File.expand_path(File.dirname(__FILE__) + \'/../ext\')' if create_ext_dir
|
26
27
|
file.puts <<EOS
|
28
|
+
require 'rubygems'
|
27
29
|
require 'gli'
|
28
30
|
|
29
31
|
include GLI
|
@@ -36,8 +38,10 @@ default_value 'the default'
|
|
36
38
|
arg_name 'The name of the argument'
|
37
39
|
flag [:f,:flagname]
|
38
40
|
EOS
|
41
|
+
first = true
|
39
42
|
commands.each do |command|
|
40
|
-
|
43
|
+
if first
|
44
|
+
file.puts <<EOS
|
41
45
|
|
42
46
|
desc 'Describe #{command} here'
|
43
47
|
arg_name 'Describe arguments to #{command} here'
|
@@ -48,14 +52,42 @@ command :#{command} do |c|
|
|
48
52
|
c.desc 'Describe a flag to #{command}'
|
49
53
|
c.default_value 'default'
|
50
54
|
c.flag :s
|
51
|
-
|
52
55
|
c.action do |global_options,options,args|
|
53
56
|
# Your command logic here
|
54
57
|
end
|
55
58
|
end
|
56
59
|
EOS
|
60
|
+
else
|
61
|
+
file.puts <<EOS
|
62
|
+
command :#{command} do |c|
|
63
|
+
c.action do |global_options,options,args|
|
64
|
+
end
|
65
|
+
end
|
66
|
+
EOS
|
67
|
+
end
|
68
|
+
first = false
|
57
69
|
end
|
58
|
-
puts
|
70
|
+
file.puts <<EOS
|
71
|
+
pre do |global,command,options,args|
|
72
|
+
# Pre logic here
|
73
|
+
# Return true to proceed; false to abourt and not call the
|
74
|
+
# chosen command
|
75
|
+
true
|
76
|
+
end
|
77
|
+
|
78
|
+
post do |global,command,options,args|
|
79
|
+
# Post logic here
|
80
|
+
end
|
81
|
+
|
82
|
+
on_error do |exception|
|
83
|
+
# Error logic here
|
84
|
+
# return false to skip default error handling
|
85
|
+
true
|
86
|
+
end
|
87
|
+
|
88
|
+
GLI.run(ARGV)
|
89
|
+
EOS
|
90
|
+
puts "Created #{bin_file}"
|
59
91
|
end
|
60
92
|
end
|
61
93
|
else
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: davetron5000-gli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Copeland
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-13 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|