drydock 0.5.6 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +14 -6
- data/README.rdoc +7 -5
- data/bin/example +159 -146
- data/drydock.gemspec +2 -2
- data/lib/drydock.rb +41 -29
- metadata +2 -2
data/CHANGES.txt
CHANGED
@@ -3,7 +3,17 @@ DRYDOCK, CHANGES
|
|
3
3
|
#### TODO ###############################
|
4
4
|
|
5
5
|
* Support putting descriptions into resource file (or __END__)
|
6
|
-
|
6
|
+
|
7
|
+
|
8
|
+
#### 0.6.0 (2009-04-22) #############################
|
9
|
+
|
10
|
+
* CHANGE: Cleaner default error message for UnknownCommand exceptions
|
11
|
+
* CHANGE: 'desc' is now 'about' (desc works, but it prints a notice)
|
12
|
+
* CHANGE: I now recommend implementing the Drydock DSL in a module.
|
13
|
+
bin/example was updated to reflect the change. This prevents Drydock
|
14
|
+
keywords from being included in the global namespace.
|
15
|
+
* ADDED: Inline commands aliases. command :cmd1, :cmd2 do; ...; end
|
16
|
+
* ADDED: Unknown commands can be directed to a trawler.
|
7
17
|
|
8
18
|
|
9
19
|
#### 0.5.6 (2009-04-22) #############################
|
@@ -11,23 +21,19 @@ DRYDOCK, CHANGES
|
|
11
21
|
* CHANGED: Interrupts now handled in rescue rather than a trap.
|
12
22
|
* ADDED: Drydock::ArgError and Drydock::OptError are rescued at runtime by default
|
13
23
|
|
14
|
-
|
15
24
|
#### 0.5.5 (2009-04-19) #############################
|
16
25
|
|
17
26
|
* CHANGED: Improved help screen formatting.
|
18
27
|
|
19
|
-
|
20
28
|
#### 0.5.4 (2009-04-15) #############################
|
21
29
|
|
22
30
|
* ADDED: Better error handling with new Drydock::ArgError and Drydock::OptError
|
23
31
|
|
24
|
-
|
25
32
|
#### 0.5.3 (2009-04-05) #############################
|
26
33
|
|
27
34
|
* FIXED: Command actions were not being handled correctly. Added rdocs to
|
28
35
|
clarify the code.
|
29
36
|
|
30
|
-
|
31
37
|
#### 0.5.2 (2009-04-04) #############################
|
32
38
|
|
33
39
|
* ADDED: before and after blocks now receive a primed reference to the
|
@@ -102,4 +108,6 @@ and sending to other methods manually.
|
|
102
108
|
#### 0.2 (2008-12-27) ###############################
|
103
109
|
|
104
110
|
* Initial release
|
105
|
-
* Forked from bmizerany/frylock
|
111
|
+
* Forked from bmizerany/frylock
|
112
|
+
|
113
|
+
|
data/README.rdoc
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
= Drydock - v0.
|
2
|
-
|
3
|
-
Inspired by github-gem and bmizerany-frylock.
|
1
|
+
= Drydock - v0.6
|
4
2
|
|
5
3
|
== Overview
|
6
4
|
|
7
|
-
Drydock is a seaworthy DSL for command line
|
5
|
+
Drydock is a seaworthy DSL for really powerful command line applications. It's contained in a single .rb file so it's easy to copy directly into your project. See below for examples.
|
8
6
|
|
9
7
|
== Install
|
10
8
|
|
@@ -38,7 +36,6 @@ See bin/example for more.
|
|
38
36
|
puts "#{$0} show-commands"
|
39
37
|
end
|
40
38
|
|
41
|
-
|
42
39
|
usage "USAGE: #{$0} laugh [-f]"
|
43
40
|
desc "The captain commands his crew to laugh"
|
44
41
|
option :f, :faster, "A boolean value. Go even faster!"
|
@@ -75,6 +72,11 @@ See bin/example for more.
|
|
75
72
|
* RDocs[http://drydock.rubyforge.org/]
|
76
73
|
* Inspiration[http://www.youtube.com/watch?v=m_wFEB4Oxlo]
|
77
74
|
|
75
|
+
== Thanks
|
76
|
+
|
77
|
+
* Solutious Inc for putting up with my endless references to the sea! (http://solutious.com)
|
78
|
+
* Blake Mizerany for the inspiration via bmizerany-frylock[http://github.com/bmizerany/frylock]
|
79
|
+
|
78
80
|
== Credits
|
79
81
|
|
80
82
|
* Delano Mandelbaum (delano@solutious.com)
|
data/bin/example
CHANGED
@@ -8,188 +8,201 @@
|
|
8
8
|
#
|
9
9
|
# If you're reading this via the Rdocs you won't see the code. See:
|
10
10
|
#
|
11
|
-
# http://github.com/delano/drydock/blob/
|
11
|
+
# http://github.com/delano/drydock/blob/master/bin/example
|
12
12
|
#
|
13
13
|
# For an example of a complex command-line application using
|
14
14
|
# Drydock, see:
|
15
15
|
#
|
16
|
-
# http://github.com/solutious/rudy
|
16
|
+
# http://github.com/solutious/rudy/blob/master/bin/rudy
|
17
17
|
#
|
18
18
|
|
19
19
|
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..')), 'lib'
|
20
20
|
|
21
21
|
require 'drydock'
|
22
|
-
extend Drydock # Tell Drydock you want its methods!
|
23
22
|
|
23
|
+
module Example
|
24
|
+
extend Drydock # Tell Drydock you want its methods!
|
25
|
+
|
26
|
+
default :welcome # The welcome command will be run if no command is given
|
27
|
+
capture :stderr # Drydock will capture STDERR and keep it in the hold.
|
28
|
+
# You can use this to suppress errors.
|
29
|
+
|
30
|
+
about "A friendly welcome to the Drydock"
|
31
|
+
command :welcome do
|
32
|
+
puts "Welcome to Drydock.", $/
|
33
|
+
puts "For available commands: #{$0} show-commands"
|
34
|
+
end
|
24
35
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
command :welcome do
|
32
|
-
puts "Welcome to Drydock.", $/
|
33
|
-
puts "For available commands: #{$0} show-commands"
|
34
|
-
end
|
35
|
-
|
36
|
-
usage "USAGE: #{$0} laugh [-f]"
|
37
|
-
desc "The captain commands his crew to laugh"
|
38
|
-
option :f, :faster, "A boolean value. Go even faster!"
|
39
|
-
command :laugh do |obj|
|
40
|
-
# +obj+ is an instance of Drydock::Command. The options you define are available
|
41
|
-
# via obj.option.name
|
36
|
+
usage "USAGE: #{$0} laugh [-f]"
|
37
|
+
about "The captain commands his crew to laugh"
|
38
|
+
option :f, :faster, "A boolean value. Go even faster!"
|
39
|
+
command :laugh do |obj|
|
40
|
+
# +obj+ is an instance of Drydock::Command. The options you define are available
|
41
|
+
# via obj.option.name
|
42
42
|
|
43
|
-
|
43
|
+
answer = !obj.option.faster ? "Sort of" : "Yes! I'm literally laughing as fast as possible."
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
end
|
45
|
+
puts "Captain Stubing: Are you laughing?"
|
46
|
+
puts "Dr. Bricker: " << answer
|
47
|
+
end
|
48
48
|
|
49
|
-
global_usage "USAGE: #{File.basename($0)} [global options] command [command options]"
|
50
|
-
global :s, :seconds, "Display values in seconds"
|
51
|
-
global :v, :verbose, "Verbosity level (i.e. -vvv is greater than -v)" do |v|
|
52
|
-
# Use instance variables to maintain values between option blocks.
|
53
|
-
# This will increment for every -v found (i.e. -vvv)
|
54
|
-
|
55
|
-
|
56
|
-
end
|
49
|
+
global_usage "USAGE: #{File.basename($0)} [global options] command [command options]"
|
50
|
+
global :s, :seconds, "Display values in seconds"
|
51
|
+
global :v, :verbose, "Verbosity level (i.e. -vvv is greater than -v)" do |v|
|
52
|
+
# Use instance variables to maintain values between option blocks.
|
53
|
+
# This will increment for every -v found (i.e. -vvv)
|
54
|
+
@val ||= 0
|
55
|
+
@val += 1
|
56
|
+
end
|
57
57
|
|
58
|
-
before do |obj|
|
59
|
-
# You can execute a block before the requests command is executed. Instance
|
60
|
-
# variables defined here will be available to all commands.
|
61
|
-
# +obj+ is a reference to the command object, just like in command blocks.
|
62
|
-
end
|
58
|
+
before do |obj|
|
59
|
+
# You can execute a block before the requests command is executed. Instance
|
60
|
+
# variables defined here will be available to all commands.
|
61
|
+
# +obj+ is a reference to the command object, just like in command blocks.
|
62
|
+
end
|
63
63
|
|
64
|
-
after do |obj|
|
65
|
-
# And this will be called after the command.
|
66
|
-
end
|
64
|
+
after do |obj|
|
65
|
+
# And this will be called after the command.
|
66
|
+
end
|
67
67
|
|
68
|
-
usage "#{$0} [-s] [-vv] date"
|
69
|
-
|
70
|
-
command :date do |obj|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
68
|
+
usage "#{$0} [-s] [-vv] date"
|
69
|
+
about "Display the current date"
|
70
|
+
command :date do |obj|
|
71
|
+
require 'time'
|
72
|
+
now = Time.now
|
73
|
+
puts "(Not verbose enough. Try adding a -v.)" if (obj.global.verbose || 0) == 1
|
74
|
+
puts "More verbosely, the date is now: " if (obj.global.verbose || 0) >= 2
|
75
|
+
puts (obj.global.seconds) ? now.to_i : now.to_s
|
76
|
+
end
|
77
77
|
|
78
78
|
|
79
|
-
ignore :options
|
80
|
-
|
81
|
-
command :rogue do |obj|
|
82
|
-
# You can use ignore :options to tell Drydock to not process the
|
83
|
-
# command-specific options.
|
84
|
-
# Unnamed arguments are available from obj.argv
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
79
|
+
ignore :options
|
80
|
+
about "This command ignores options"
|
81
|
+
command :rogue do |obj|
|
82
|
+
# You can use ignore :options to tell Drydock to not process the
|
83
|
+
# command-specific options.
|
84
|
+
# Unnamed arguments are available from obj.argv
|
85
|
+
if obj.argv.empty?
|
86
|
+
puts "Had you supplied some arguments, I would have ignored them."
|
87
|
+
else
|
88
|
+
puts "Hi! You supplied some arguments but I ignored them."
|
89
|
+
puts "They're all still here in this array: %s" % obj.argv.join(', ')
|
90
|
+
end
|
90
91
|
end
|
91
|
-
end
|
92
92
|
|
93
|
-
class JohnWestSmokedOysters < Drydock::Command
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
end
|
93
|
+
class JohnWestSmokedOysters < Drydock::Command
|
94
|
+
# You can write your own command classes by inheriting from Drydock::Command
|
95
|
+
# and referencing it in the command definition.
|
96
|
+
def ahoy!; p "matey"; end
|
97
|
+
end
|
98
98
|
|
99
|
-
|
100
|
-
command :oysters => JohnWestSmokedOysters do |obj|
|
101
|
-
|
102
|
-
end
|
99
|
+
about "Do something with John West's Smoked Oysters"
|
100
|
+
command :oysters => JohnWestSmokedOysters do |obj|
|
101
|
+
p obj # => #<JohnWestSmokedOysters:0x42179c ... >
|
102
|
+
end
|
103
103
|
|
104
|
-
|
105
|
-
command :ahoy! => JohnWestSmokedOysters
|
106
|
-
# If you don't provide a block, Drydock will call JohnWestSmokedOysters#ahoy!
|
104
|
+
about "My way of saying hello!"
|
105
|
+
command :ahoy! => JohnWestSmokedOysters
|
106
|
+
# If you don't provide a block, Drydock will call JohnWestSmokedOysters#ahoy!
|
107
107
|
|
108
108
|
|
109
|
-
require 'yaml'
|
109
|
+
require 'yaml'
|
110
110
|
|
111
|
-
usage 'ruby bin/example uri -c -d " " -t 15 http://solutious.com/'
|
112
|
-
usage 'echo "http://solutious.com/" | ruby bin/example uri -c -d " " -t 15'
|
113
|
-
|
114
|
-
option :c, :check, "Check response codes for each URI"
|
115
|
-
option :d, :delim, String, "Output delimiter"
|
116
|
-
option :t, :timeout, Float, "Timeout value for HTTP request" do |v|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
end
|
122
|
-
argv :uris
|
123
|
-
command :uri do |obj|
|
124
|
-
# This command processes the output of the stdin block (below this definition).
|
125
|
-
# The output of that block is available as obj.stdin. If there is no stdin block
|
126
|
-
# obj.stdin will be STDIN's IO object.
|
127
|
-
|
128
|
-
require 'net/http'
|
129
|
-
require 'uri'
|
130
|
-
require 'timeout'
|
131
|
-
|
132
|
-
uris = []
|
133
|
-
uris += obj.stdin if obj.stdin
|
134
|
-
uris += obj.argv.uris if obj.argv.uris
|
111
|
+
usage 'ruby bin/example uri -c -d " " -t 15 http://solutious.com/'
|
112
|
+
usage 'echo "http://solutious.com/" | ruby bin/example uri -c -d " " -t 15'
|
113
|
+
about "Check for broken URIs"
|
114
|
+
option :c, :check, "Check response codes for each URI"
|
115
|
+
option :d, :delim, String, "Output delimiter"
|
116
|
+
option :t, :timeout, Float, "Timeout value for HTTP request" do |v|
|
117
|
+
# You can provide an block to process the option value.
|
118
|
+
# This block must return the final value.
|
119
|
+
v = 10 if (v > 10)
|
120
|
+
v
|
121
|
+
end
|
122
|
+
argv :uris
|
135
123
|
|
136
|
-
|
137
|
-
|
138
|
-
|
124
|
+
command :uri do |obj|
|
125
|
+
# This command processes the output of the stdin block (below this definition).
|
126
|
+
# The output of that block is available as obj.stdin. If there is no stdin block
|
127
|
+
# obj.stdin will be STDIN's IO object.
|
128
|
+
|
129
|
+
require 'net/http'
|
130
|
+
require 'uri'
|
131
|
+
require 'timeout'
|
139
132
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
exit 0
|
144
|
-
end
|
133
|
+
uris = []
|
134
|
+
uris += obj.stdin if obj.stdin
|
135
|
+
uris += obj.argv.uris if obj.argv.uris
|
145
136
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
end
|
137
|
+
delim = obj.option.delim || ','
|
138
|
+
timeout = obj.option.timeout || 5
|
139
|
+
code = :notchecked # The default code when :check is false
|
150
140
|
|
151
|
-
|
152
|
-
|
141
|
+
if uris.empty?
|
142
|
+
puts "Frylock: You didn't provide any URIs. "
|
143
|
+
puts "Master Shake: Ya, see #{$0} #{obj.alias} -h"
|
144
|
+
exit 0
|
145
|
+
end
|
153
146
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
147
|
+
uris.each_with_index do |uri, index|
|
148
|
+
code = response_code(uri, timeout) if (obj.option.check)
|
149
|
+
puts [index+1, uri, code].join(delim)
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
158
153
|
|
159
|
-
|
160
|
-
#
|
161
|
-
# The
|
154
|
+
about "Prints the alias used to access the command"
|
155
|
+
# We can define command aliases by providing a list of command
|
156
|
+
# names. The first name is still consider to be the main name.
|
157
|
+
command :printalias, :reveal do |obj|
|
158
|
+
puts "This is printalias!"
|
159
|
+
if (obj.alias == obj.cmd)
|
160
|
+
puts "You did not use an alias"
|
161
|
+
else
|
162
|
+
puts "You used the alias " << obj.alias
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
stdin do |stdin, output|
|
167
|
+
# Pre-process STDIN for all commands. This example returns an array of lines.
|
168
|
+
# The command processuris uses this array.
|
162
169
|
|
163
|
-
|
164
|
-
|
165
|
-
|
170
|
+
# We only want piped data. If this is not included
|
171
|
+
# execution will wait for input from the user.
|
172
|
+
unless stdin.tty?
|
166
173
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
174
|
+
while !stdin.eof? do
|
175
|
+
line = stdin.readline
|
176
|
+
line.chomp!
|
177
|
+
(output ||= []) << line
|
178
|
+
end
|
172
179
|
|
180
|
+
end
|
181
|
+
output
|
173
182
|
end
|
174
|
-
output
|
175
|
-
end
|
176
183
|
|
177
|
-
|
178
|
-
|
179
|
-
#
|
180
|
-
#
|
181
|
-
#
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
response
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
184
|
+
|
185
|
+
# And one final feature for the intrepid swabbies like myself.
|
186
|
+
# Drydock can handle unknown commands by catching them with a
|
187
|
+
# trawler. It's like the captain of all aliases. Just specify
|
188
|
+
# the command name to direct all unknown commands to. Simple!
|
189
|
+
trawler :printalias
|
190
|
+
|
191
|
+
|
192
|
+
# Return the HTTP response code for the given URI. Used by
|
193
|
+
# uri command.
|
194
|
+
#
|
195
|
+
# +uri+ A valid HTTP URI
|
196
|
+
# +duration+ The timeout threshold (in seconds) for the request.
|
197
|
+
def response_code(uri_str, duration=5) #:nodoc:
|
198
|
+
response = :unavailable
|
199
|
+
begin
|
200
|
+
uri = (uri_str.kind_of? URI::HTTP) ? uri_str : URI.parse(uri_str)
|
201
|
+
timeout(duration) do
|
202
|
+
response = Net::HTTP.get_response(uri).code
|
203
|
+
end
|
204
|
+
rescue Exception => ex
|
205
|
+
end
|
206
|
+
response
|
192
207
|
end
|
193
|
-
response
|
194
208
|
end
|
195
|
-
|
data/drydock.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
@spec = Gem::Specification.new do |s|
|
2
2
|
s.name = %q{drydock}
|
3
|
-
s.version = "0.
|
4
|
-
s.date = %q{2009-04-
|
3
|
+
s.version = "0.6.0"
|
4
|
+
s.date = %q{2009-04-28}
|
5
5
|
s.specification_version = 1 if s.respond_to? :specification_version=
|
6
6
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
7
7
|
|
data/lib/drydock.rb
CHANGED
@@ -75,7 +75,7 @@ module Drydock
|
|
75
75
|
# end
|
76
76
|
#
|
77
77
|
class Command
|
78
|
-
VERSION = 0.
|
78
|
+
VERSION = 0.6
|
79
79
|
# The canonical name of the command (the one used in the command definition). If you
|
80
80
|
# inherit from this class and add a method named +cmd+, you can leave omit the block
|
81
81
|
# in the command definition. That method will be called instead. See bin/examples.
|
@@ -266,7 +266,6 @@ module Drydock
|
|
266
266
|
|
267
267
|
cmd_names_sorted = cmds.keys.sort{ |a,b| a.to_s <=> b.to_s }
|
268
268
|
|
269
|
-
|
270
269
|
if @global.quiet
|
271
270
|
puts "Commands: "
|
272
271
|
line = []
|
@@ -351,7 +350,7 @@ end
|
|
351
350
|
module Drydock
|
352
351
|
extend self
|
353
352
|
|
354
|
-
VERSION = 0.
|
353
|
+
VERSION = 0.6
|
355
354
|
|
356
355
|
@@project = nil
|
357
356
|
|
@@ -374,9 +373,11 @@ module Drydock
|
|
374
373
|
@@command_index_map = {}
|
375
374
|
@@command_argv_names = [] # an array of names for values of argv
|
376
375
|
|
377
|
-
@@capture = nil
|
376
|
+
@@capture = nil # contains one of :stdout, :stderr
|
378
377
|
@@captured = nil
|
379
378
|
|
379
|
+
@@trawler = nil
|
380
|
+
|
380
381
|
public
|
381
382
|
# Enable or disable debug output.
|
382
383
|
#
|
@@ -494,7 +495,6 @@ module Drydock
|
|
494
495
|
get_current_option_parser.banner << "USAGE: #{msg}" << $/
|
495
496
|
end
|
496
497
|
|
497
|
-
|
498
498
|
# Tell the Drydock parser to ignore something.
|
499
499
|
# Drydock will currently only listen to you if you tell it to "ignore :options",
|
500
500
|
# otherwise it will ignore you!
|
@@ -581,7 +581,7 @@ module Drydock
|
|
581
581
|
# end
|
582
582
|
#
|
583
583
|
def command(*cmds, &b)
|
584
|
-
cmd = cmds.
|
584
|
+
cmd = cmds.shift # Should we accept aliases here?
|
585
585
|
|
586
586
|
if cmd.is_a? Hash
|
587
587
|
raise "#{cmd.values.first} is not a subclass of Drydock::Command" unless cmd.values.first.ancestors.member?(Drydock::Command)
|
@@ -612,6 +612,10 @@ module Drydock
|
|
612
612
|
@@command_index_map[c.cmd] = @@command_index
|
613
613
|
@@command_index += 1 # This will point to the next command
|
614
614
|
|
615
|
+
# Created aliases to the command using any additional command names
|
616
|
+
# i.e. command :something, :sumpin => Something
|
617
|
+
cmds.each { |aliaz| command_alias(cmd, aliaz); } unless cmds.empty?
|
618
|
+
|
615
619
|
c # Return the Command object
|
616
620
|
end
|
617
621
|
|
@@ -651,12 +655,32 @@ module Drydock
|
|
651
655
|
@@commands.keys.collect { |cmd| decanonize(cmd); }
|
652
656
|
end
|
653
657
|
|
658
|
+
# The trawler catches any and all unknown commands that pass through
|
659
|
+
# Drydock. It's like the captain of aliases.
|
660
|
+
# +cmd+ is the name of the command to direct unknowns to.
|
661
|
+
#
|
662
|
+
# trawler :command_name
|
663
|
+
#
|
664
|
+
def trawler(cmd)
|
665
|
+
@@trawler = cmd
|
666
|
+
end
|
667
|
+
|
668
|
+
# Has the trawler been set?
|
669
|
+
def trawler?
|
670
|
+
!@@trawler.nil? && !@@trawler.empty?
|
671
|
+
end
|
672
|
+
|
654
673
|
# Provide a description for a command
|
655
|
-
def
|
674
|
+
def about(txt)
|
656
675
|
@@command_descriptions += [txt]
|
657
676
|
return if get_current_option_parser.is_a?(Symbol)
|
658
677
|
get_current_option_parser.on "ABOUT: #{txt}"
|
659
678
|
end
|
679
|
+
# Deprecated. Use about.
|
680
|
+
def desc(txt)
|
681
|
+
STDERR.puts "'desc' is deprecated. Please use 'about' instead."
|
682
|
+
about(txt)
|
683
|
+
end
|
660
684
|
|
661
685
|
# Returns true if automatic execution is enabled.
|
662
686
|
def run?
|
@@ -683,12 +707,8 @@ module Drydock
|
|
683
707
|
return if has_run?
|
684
708
|
@@has_run = true
|
685
709
|
raise NoCommandsDefined.new if commands.empty?
|
686
|
-
global_options, cmd_name, command_options, argv = process_arguments(argv)
|
687
|
-
|
688
|
-
cmd_name ||= default_command
|
689
|
-
|
690
|
-
raise UnknownCommand.new(cmd_name) unless command?(cmd_name)
|
691
710
|
|
711
|
+
global_options, cmd_name, command_options, argv = process_arguments(argv)
|
692
712
|
stdin = (defined? @@stdin_block) ? @@stdin_block.call(stdin, []) : stdin
|
693
713
|
|
694
714
|
command_obj = get_command(cmd_name)
|
@@ -811,7 +831,12 @@ module Drydock
|
|
811
831
|
|
812
832
|
global_options = @@global_opts_parser.getopts(argv)
|
813
833
|
cmd_name = (argv.empty?) ? @@default_command : argv.shift
|
814
|
-
|
834
|
+
|
835
|
+
unless command?(cmd_name)
|
836
|
+
raise UnknownCommand.new(cmd_name) unless trawler?
|
837
|
+
raise UnknownCommand.new(@@trawler) unless command?(@@trawler)
|
838
|
+
command_alias(@@trawler, cmd_name)
|
839
|
+
end
|
815
840
|
|
816
841
|
cmd = get_command(cmd_name)
|
817
842
|
|
@@ -825,22 +850,6 @@ module Drydock
|
|
825
850
|
command_options = command_parser.getopts(argv)
|
826
851
|
end
|
827
852
|
|
828
|
-
# TODO: Remove this chunk for method creation. We now use OpenStruct.
|
829
|
-
# Add accessors to the Drydock::Command object
|
830
|
-
# for the global and command specific options
|
831
|
-
#[global_option_names, (command_option_names[get_command_index(cmd_name)] || [])].flatten.each do |n|
|
832
|
-
# unless cmd.respond_to?(n)
|
833
|
-
# cmd.class.send(:define_method, n) do
|
834
|
-
# instance_variable_get("@#{n}")
|
835
|
-
# end
|
836
|
-
# end
|
837
|
-
# unless cmd.respond_to?("#{n}=")
|
838
|
-
# cmd.class.send(:define_method, "#{n}=") do |val|
|
839
|
-
# instance_variable_set("@#{n}", val)
|
840
|
-
# end
|
841
|
-
# end
|
842
|
-
#end
|
843
|
-
|
844
853
|
[global_options, cmd_name, command_options, argv]
|
845
854
|
end
|
846
855
|
|
@@ -895,6 +904,9 @@ at_exit {
|
|
895
904
|
rescue Drydock::ArgError, Drydock::OptError=> ex
|
896
905
|
STDERR.puts ex.message
|
897
906
|
STDERR.puts ex.usage
|
907
|
+
rescue Drydock::UnknownCommand => ex
|
908
|
+
STDERR.puts ex.message
|
909
|
+
STDERR.puts ex.backtrace if Drydock.debug?
|
898
910
|
rescue => ex
|
899
911
|
STDERR.puts "ERROR (#{ex.class.to_s}): #{ex.message}"
|
900
912
|
STDERR.puts ex.backtrace if Drydock.debug?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: drydock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Delano Mandelbaum
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-28 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|