drydock 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +16 -0
- data/LICENSE.txt +22 -0
- data/README.rdoc +70 -0
- data/Rakefile +72 -0
- data/bin/example +152 -0
- data/doc/classes/Drydock.html +535 -0
- data/doc/classes/Drydock/Command.html +180 -0
- data/doc/classes/Drydock/InvalidArgument.html +118 -0
- data/doc/classes/Drydock/MissingArgument.html +88 -0
- data/doc/classes/Drydock/NoCommandsDefined.html +88 -0
- data/doc/classes/Drydock/UnknownCommand.html +118 -0
- data/doc/created.rid +1 -0
- data/doc/files/CHANGES_txt.html +100 -0
- data/doc/files/LICENSE_txt.html +87 -0
- data/doc/files/README_rdoc.html +119 -0
- data/doc/files/bin/example.html +104 -0
- data/doc/files/lib/drydock_rb.html +75 -0
- data/doc/fr_class_index.html +19 -0
- data/doc/fr_file_index.html +24 -0
- data/doc/fr_method_index.html +4459 -0
- data/doc/index.html +15 -0
- data/doc/rdoc-style.css +319 -0
- data/drydock.gemspec +53 -0
- data/lib/drydock.rb +482 -0
- data/test/command_test.rb +40 -0
- metadata +90 -0
data/CHANGES.txt
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
DRYDOCK, CHANGES
|
2
|
+
|
3
|
+
#### 0.3 (2009-02-05) ###############################
|
4
|
+
|
5
|
+
* Added support for custom Drydock::Commands objects
|
6
|
+
* Global and command-specific options are now available as
|
7
|
+
attributes of the Drydock::Commands class instance.
|
8
|
+
* Automatic execution
|
9
|
+
* Now in a single file (lib/drydock.rb)
|
10
|
+
* Started adding tests
|
11
|
+
* Improved documentation
|
12
|
+
|
13
|
+
#### 0.2 (2008-12-27) ###############################
|
14
|
+
|
15
|
+
* Initial release
|
16
|
+
* Forked from bmizerany/frylock
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2008 Delano Mandelbaum
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
= Drydock - v0.3
|
2
|
+
|
3
|
+
Inspired by github-gem and bmizerany-frylock.
|
4
|
+
|
5
|
+
== Overview
|
6
|
+
|
7
|
+
Drydock is a seaworthy DSL for command line apps. It is contained in a single .rb which can be copied directly into your project.
|
8
|
+
|
9
|
+
== Install
|
10
|
+
|
11
|
+
One of:
|
12
|
+
|
13
|
+
* gem install drydock
|
14
|
+
* copy lib/drydock.rb into your lib directory.
|
15
|
+
|
16
|
+
Or for GitHub fans:
|
17
|
+
|
18
|
+
* git clone git://github.com/delano/drydock.git
|
19
|
+
* gem install delano-drydock
|
20
|
+
|
21
|
+
== Examples
|
22
|
+
|
23
|
+
See bin/example for more.
|
24
|
+
|
25
|
+
require 'rubygems'
|
26
|
+
require 'drydock'
|
27
|
+
|
28
|
+
default :welcome
|
29
|
+
|
30
|
+
before do
|
31
|
+
# You can execute a block before the requests command is executed. Instance
|
32
|
+
# variables defined here will be available to all commands.
|
33
|
+
end
|
34
|
+
|
35
|
+
command :welcome do
|
36
|
+
# Example: ruby bin/example
|
37
|
+
|
38
|
+
puts "Meatwad: Science is a mystery to man, isn't it Frylock?"
|
39
|
+
print "Frylock: At least we have some commands: "
|
40
|
+
|
41
|
+
# The commands method returns a hash of Frylock::Command objects
|
42
|
+
puts commands.keys.inject([]) { |list, command| list << command.to_s }.sort.join(', ')
|
43
|
+
end
|
44
|
+
|
45
|
+
option :f, :found, "A boolean value. Did you find the car?"
|
46
|
+
command :findcar do |options|
|
47
|
+
# +options+ is a hash containing the options defined above
|
48
|
+
# Example: ruby bin/example -f findcar
|
49
|
+
|
50
|
+
puts "Frylock: So, did they ever find your car?"
|
51
|
+
|
52
|
+
# The keys to the hash are the long string from the option definition.
|
53
|
+
# If only the short string is provided, those will be used instead (i.e. :f).
|
54
|
+
puts (!options[:found]) ? "Carl: No" :
|
55
|
+
"Carl: Oh, they found part of it, hangin' from a trestle near the turnpike."
|
56
|
+
end
|
57
|
+
|
58
|
+
== More Information
|
59
|
+
|
60
|
+
http://www.youtube.com/watch?v=m_wFEB4Oxlo
|
61
|
+
|
62
|
+
== Credits
|
63
|
+
|
64
|
+
* Delano Mandelbaum (delano@solutious.com)
|
65
|
+
* Bernie Kopell (bernie@solutious.com)
|
66
|
+
|
67
|
+
|
68
|
+
== License
|
69
|
+
|
70
|
+
See LICENSE.txt
|
data/Rakefile
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
require 'hanna/rdoctask'
|
5
|
+
require 'fileutils'
|
6
|
+
include FileUtils
|
7
|
+
|
8
|
+
task :default => :test
|
9
|
+
|
10
|
+
# SPECS ===============================================================
|
11
|
+
|
12
|
+
desc 'Run specs with unit test style output'
|
13
|
+
task :test do |t|
|
14
|
+
sh "ruby tests/*_test.rb"
|
15
|
+
end
|
16
|
+
|
17
|
+
# PACKAGE =============================================================
|
18
|
+
|
19
|
+
|
20
|
+
require File.dirname(__FILE__) + "/lib/drydock"
|
21
|
+
load "drydock.gemspec"
|
22
|
+
|
23
|
+
version = Drydock::VERSION.to_s
|
24
|
+
|
25
|
+
Drydock.run = false
|
26
|
+
|
27
|
+
Rake::GemPackageTask.new(@spec) do |p|
|
28
|
+
p.need_tar = true if RUBY_PLATFORM !~ /mswin/
|
29
|
+
end
|
30
|
+
|
31
|
+
task :release => [ :rdoc, :package ]
|
32
|
+
|
33
|
+
task :install => [ :rdoc, :package ] do
|
34
|
+
sh %{sudo gem install pkg/#{name}-#{version}.gem}
|
35
|
+
end
|
36
|
+
|
37
|
+
task :uninstall => [ :clean ] do
|
38
|
+
sh %{sudo gem uninstall #{name}}
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
# Rubyforge Release / Publish Tasks ==================================
|
43
|
+
|
44
|
+
desc 'Publish website to rubyforge'
|
45
|
+
task 'publish:doc' => 'doc/index.html' do
|
46
|
+
sh 'scp -rp doc/* rubyforge.org:/var/www/gforge-projects/drydock/'
|
47
|
+
end
|
48
|
+
|
49
|
+
task 'publish:gem' => [:package] do |t|
|
50
|
+
sh <<-end
|
51
|
+
rubyforge add_release drydock drydock #{@spec.version} pkg/drydock-#{@spec.version}.gem &&
|
52
|
+
rubyforge add_file drydock drydock #{@spec.version} pkg/drydock-#{@spec.version}.tar.gz
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
Rake::RDocTask.new do |t|
|
58
|
+
t.rdoc_dir = 'doc'
|
59
|
+
t.title = "Drydock, A seaworthy DSL for command-line apps."
|
60
|
+
t.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
|
61
|
+
t.options << '--charset' << 'utf-8'
|
62
|
+
t.rdoc_files.include('LICENSE.txt')
|
63
|
+
t.rdoc_files.include('README.rdoc')
|
64
|
+
t.rdoc_files.include('CHANGES.txt')
|
65
|
+
t.rdoc_files.include('bin/*')
|
66
|
+
t.rdoc_files.include('lib/*.rb')
|
67
|
+
end
|
68
|
+
|
69
|
+
CLEAN.include [ 'pkg', '*.gem', '.config', 'doc' ]
|
70
|
+
|
71
|
+
|
72
|
+
|
data/bin/example
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..')), 'lib'
|
4
|
+
|
5
|
+
require 'drydock'
|
6
|
+
|
7
|
+
default :welcome
|
8
|
+
|
9
|
+
before do
|
10
|
+
# You can execute a block before the requests command is executed. Instance
|
11
|
+
# variables defined here will be available to all commands.
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
# And this will be called after the command.
|
16
|
+
end
|
17
|
+
|
18
|
+
command :welcome do
|
19
|
+
# Example: ruby bin/example
|
20
|
+
|
21
|
+
puts "Meatwad: Science is a mystery to man, isn't it Frylock?"
|
22
|
+
print "Frylock: At least we have some commands: "
|
23
|
+
|
24
|
+
# The commands method returns a hash of Drydock::Command objects
|
25
|
+
puts commands.keys.inject([]) { |list, command| list << command.to_s }.sort.join(', ')
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
option :f, :found, "A boolean value. Did you find the car?"
|
30
|
+
command :findcar do |obj|
|
31
|
+
# +obj+ is the Drylock::Command object instance. It contains accessors for all options.
|
32
|
+
# Example: ruby bin/example -f findcar
|
33
|
+
|
34
|
+
puts "Frylock: So, did they ever find your car?"
|
35
|
+
|
36
|
+
# The keys to the hash are the long string from the option definition.
|
37
|
+
# If only the short string is provided, those will be used instead (i.e. :f).
|
38
|
+
puts (!obj.found) ? "Carl: No" :
|
39
|
+
"Carl: Oh, they found part of it, hangin' from a trestle near the turnpike."
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
global_usage "USAGE: #{File.basename($0)} [global options] command [command options]"
|
45
|
+
global_option :s, :seconds, "Display values in seconds"
|
46
|
+
global_option :v, :verbose, "Verbosity level (i.e. -vvv is greater than -v)" do |v|
|
47
|
+
# Use instance variables to maintain values between option blocks.
|
48
|
+
# This will increment for every -v found (i.e. -vvv)
|
49
|
+
@val ||= 0
|
50
|
+
@val += 1
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
usage "#{$0} [-s] [-vv] date"
|
55
|
+
command :date do |obj, argv|
|
56
|
+
# +argv+ is an array containing the unnamed arguments
|
57
|
+
require 'time'
|
58
|
+
now = Time.now
|
59
|
+
puts "(Not verbose enough. Try adding a -v.)" if (obj.verbose || 0) == 1
|
60
|
+
puts "More verbosely, the date is now: " if (obj.verbose || 0) >= 2
|
61
|
+
puts (obj.seconds) ? now.to_i : now.to_s
|
62
|
+
end
|
63
|
+
|
64
|
+
usage "#{$0} rogue"
|
65
|
+
ignore :options
|
66
|
+
command :rogue do |obj, argv|
|
67
|
+
# You can use ignore :options to tell Drydock to not process the
|
68
|
+
# command-specific options.
|
69
|
+
if argv.empty?
|
70
|
+
puts "Had you supplied some arguments, I would have ignored them."
|
71
|
+
else
|
72
|
+
puts "Hi! You supplied some arguments but I ignored them."
|
73
|
+
puts "They're all still here in this array: %s" % argv.join(', ')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
option :c, :check, "Check response codes for each URI"
|
78
|
+
option :d, :delim, String, "Output delimiter"
|
79
|
+
option :t, :timeout, Float, "Timeout value for HTTP request" do |v|
|
80
|
+
# You can provide an block to process the option value.
|
81
|
+
# This block must return the final value.
|
82
|
+
v = 10 if (v > 10)
|
83
|
+
v
|
84
|
+
end
|
85
|
+
|
86
|
+
usage 'echo "http://github.com/" | ruby bin/example process -c -d " " -t 15 http://solutious.com/'
|
87
|
+
command :processuri do |obj, argv, stdin|
|
88
|
+
# +cmd+ is the string used to evoke this command. Useful with alias_command (see below).
|
89
|
+
# +stdin+ is either an IO object or a custom object defined with a stdin block (see below)
|
90
|
+
|
91
|
+
require 'net/http'
|
92
|
+
require 'uri'
|
93
|
+
require 'timeout'
|
94
|
+
|
95
|
+
uris = [stdin, argv].flatten # Combine the argv and stdin arrays
|
96
|
+
delim = obj.delim || ','
|
97
|
+
timeout = obj.timeout || 5
|
98
|
+
code = :notchecked # The default code when :check is false
|
99
|
+
|
100
|
+
if uris.empty?
|
101
|
+
puts "Frylock: You didn't provide any URIs. "
|
102
|
+
puts "Master Shake: Ya, see #{$0} #{obj.alias} -h"
|
103
|
+
exit 0
|
104
|
+
end
|
105
|
+
|
106
|
+
uris.each_with_index do |uri, index|
|
107
|
+
code = response_code(uri, timeout) if (obj.check)
|
108
|
+
puts [index+1, uri, code].join(delim)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
alias_command :checkuri, :processuri
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
stdin do |stdin, output|
|
117
|
+
# Pre-process STDIN for all commands. This example returns an array of lines.
|
118
|
+
# The command processuris uses this array.
|
119
|
+
|
120
|
+
# We only want piped data. If this is not included
|
121
|
+
# execution will wait for input from the user.
|
122
|
+
unless stdin.tty?
|
123
|
+
|
124
|
+
while !stdin.eof? do
|
125
|
+
line = stdin.readline
|
126
|
+
line.chomp!
|
127
|
+
(output ||= []) << line
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
output
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
# response_code
|
137
|
+
#
|
138
|
+
# return the HTTP response code for the given URI
|
139
|
+
# +uri+ A valid HTTP URI
|
140
|
+
# +duration+ The timeout threshold (in seconds) for the request.
|
141
|
+
def response_code(uri_str, duration=5)
|
142
|
+
response = :unavailable
|
143
|
+
begin
|
144
|
+
uri = (uri_str.kind_of? URI::HTTP) ? uri_str : URI.parse(uri_str)
|
145
|
+
timeout(duration) do
|
146
|
+
response = Net::HTTP.get_response(uri).code
|
147
|
+
end
|
148
|
+
rescue Exception => ex
|
149
|
+
end
|
150
|
+
response
|
151
|
+
end
|
152
|
+
|
@@ -0,0 +1,535 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
2
|
+
<html lang='en'>
|
3
|
+
<head>
|
4
|
+
<title>Module: Drydock [Drydock, A seaworthy DSL for command-line apps.]</title>
|
5
|
+
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
|
6
|
+
<link href='.././rdoc-style.css' media='screen' rel='stylesheet' type='text/css'>
|
7
|
+
<script type='text/javascript'>
|
8
|
+
//<![CDATA[
|
9
|
+
function popupCode(url) {
|
10
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
11
|
+
}
|
12
|
+
|
13
|
+
function toggleCode(id) {
|
14
|
+
var code = document.getElementById(id)
|
15
|
+
|
16
|
+
code.style.display = code.style.display != 'block' ? 'block' : 'none'
|
17
|
+
return true
|
18
|
+
}
|
19
|
+
|
20
|
+
// Make codeblocks hidden by default
|
21
|
+
document.writeln('<' + 'style type="text/css">.method .source pre { display: none }<\/style>')
|
22
|
+
//]]>
|
23
|
+
</script>
|
24
|
+
</head>
|
25
|
+
<body class='page'>
|
26
|
+
<div class='class' id='wrapper'>
|
27
|
+
<div class='header'>
|
28
|
+
<h1 class='name'>
|
29
|
+
<span class='type'>Module</span>
|
30
|
+
Drydock
|
31
|
+
</h1>
|
32
|
+
<ol class='paths'>
|
33
|
+
<li>
|
34
|
+
<a href="../files/lib/drydock_rb.html">lib/drydock.rb</a>
|
35
|
+
</li>
|
36
|
+
</ol>
|
37
|
+
</div>
|
38
|
+
<div id='content'>
|
39
|
+
<div id='text'>
|
40
|
+
<div id='description'>
|
41
|
+
<hr size="1"></hr><p>
|
42
|
+
<a href="Drydock.html">Drydock</a> is a DSL for command-line apps. See <a
|
43
|
+
href="../files/bin/example.html">bin/example</a> for usage examples.
|
44
|
+
</p>
|
45
|
+
</div>
|
46
|
+
<div id='method-list'>
|
47
|
+
<h2>Methods</h2>
|
48
|
+
<h3>public instance</h3>
|
49
|
+
<ol>
|
50
|
+
<li><a href="#M000007">after</a></li>
|
51
|
+
<li><a href="#M000015">alias_command</a></li>
|
52
|
+
<li><a href="#M000006">before</a></li>
|
53
|
+
<li><a href="#M000014">command</a></li>
|
54
|
+
<li><a href="#M000016">command_alias</a></li>
|
55
|
+
<li><a href="#M000017">commands</a></li>
|
56
|
+
<li><a href="#M000002">debug</a></li>
|
57
|
+
<li><a href="#M000003">debug?</a></li>
|
58
|
+
<li><a href="#M000004">default</a></li>
|
59
|
+
<li><a href="#M000010">get_current_option_parser</a></li>
|
60
|
+
<li><a href="#M000012">global_option</a></li>
|
61
|
+
<li><a href="#M000008">global_usage</a></li>
|
62
|
+
<li><a href="#M000020">has_run?</a></li>
|
63
|
+
<li><a href="#M000011">ignore</a></li>
|
64
|
+
<li><a href="#M000013">option</a></li>
|
65
|
+
<li><a href="#M000021">run!</a></li>
|
66
|
+
<li><a href="#M000019">run=</a></li>
|
67
|
+
<li><a href="#M000018">run?</a></li>
|
68
|
+
<li><a href="#M000005">stdin</a></li>
|
69
|
+
<li><a href="#M000009">usage</a></li>
|
70
|
+
</ol>
|
71
|
+
</div>
|
72
|
+
<div id='section'>
|
73
|
+
<div id='class-list'>
|
74
|
+
<h2>Classes and Modules</h2>
|
75
|
+
Class <a href="Drydock/Command.html" class="link">Drydock::Command</a><br />
|
76
|
+
Class <a href="Drydock/InvalidArgument.html" class="link">Drydock::InvalidArgument</a><br />
|
77
|
+
Class <a href="Drydock/MissingArgument.html" class="link">Drydock::MissingArgument</a><br />
|
78
|
+
Class <a href="Drydock/NoCommandsDefined.html" class="link">Drydock::NoCommandsDefined</a><br />
|
79
|
+
Class <a href="Drydock/UnknownCommand.html" class="link">Drydock::UnknownCommand</a><br />
|
80
|
+
</div>
|
81
|
+
<div id='constants-list'>
|
82
|
+
<h2>Constants</h2>
|
83
|
+
<div class='name-list'>
|
84
|
+
<table summary='Constants'>
|
85
|
+
<tr class='top-aligned-row context-row'>
|
86
|
+
<td class='context-item-name'>VERSION</td>
|
87
|
+
<td>=</td>
|
88
|
+
<td class='context-item-value'>0.3</td>
|
89
|
+
</tr>
|
90
|
+
</table>
|
91
|
+
</div>
|
92
|
+
</div>
|
93
|
+
<div id='methods'>
|
94
|
+
<h2>Public instance methods</h2>
|
95
|
+
<div class='public-instance method' id='method-M000007'>
|
96
|
+
<a name='M000007'> </a>
|
97
|
+
<div class='synopsis'>
|
98
|
+
<span class='name'>after</span>
|
99
|
+
<span class='arguments'>(&b)</span>
|
100
|
+
</div>
|
101
|
+
<div class='description'>
|
102
|
+
<p>
|
103
|
+
Define a block to be called after the command. This is useful for stopping,
|
104
|
+
closing, etc... the stuff in the before block.
|
105
|
+
</p>
|
106
|
+
</div>
|
107
|
+
<div class='source'>
|
108
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000007-source'); return false">
|
109
|
+
[show source]
|
110
|
+
</a>
|
111
|
+
<pre id='M000007-source'> <span class="ruby-comment cmt"># File lib/drydock.rb, line 165</span>
165: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">after</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">b</span>)
166: <span class="ruby-ivar">@@after_block</span> = <span class="ruby-identifier">b</span>
167: <span class="ruby-keyword kw">end</span></pre>
|
112
|
+
</div>
|
113
|
+
</div>
|
114
|
+
<div class='public-instance method' id='method-M000015'>
|
115
|
+
<a name='M000015'> </a>
|
116
|
+
<div class='synopsis'>
|
117
|
+
<span class='name'>alias_command</span>
|
118
|
+
<span class='arguments'>(aliaz, cmd)</span>
|
119
|
+
</div>
|
120
|
+
<div class='description'>
|
121
|
+
<p>
|
122
|
+
Used to create an alias to a defined command. Here’s an example:
|
123
|
+
</p>
|
124
|
+
<pre>command :task do; ...; end
alias_command :pointer, :task</pre>
|
125
|
+
<p>
|
126
|
+
Either name can be used on the command-line:
|
127
|
+
</p>
|
128
|
+
<pre>$ script task [options]
$ script pointer [options]</pre>
|
129
|
+
<p>
|
130
|
+
Inside of the command definition, you have access to the command name that
|
131
|
+
was used via obj.alias.
|
132
|
+
</p>
|
133
|
+
</div>
|
134
|
+
<div class='source'>
|
135
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000015-source'); return false">
|
136
|
+
[show source]
|
137
|
+
</a>
|
138
|
+
<pre id='M000015-source'> <span class="ruby-comment cmt"># File lib/drydock.rb, line 274</span>
274: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">alias_command</span>(<span class="ruby-identifier">aliaz</span>, <span class="ruby-identifier">cmd</span>)
275: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">commands</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">cmd</span>
276: <span class="ruby-ivar">@@commands</span>[<span class="ruby-identifier">aliaz</span>] = <span class="ruby-identifier">commands</span>[<span class="ruby-identifier">cmd</span>]
277: <span class="ruby-keyword kw">end</span></pre>
|
139
|
+
</div>
|
140
|
+
</div>
|
141
|
+
<div class='public-instance method' id='method-M000006'>
|
142
|
+
<a name='M000006'> </a>
|
143
|
+
<div class='synopsis'>
|
144
|
+
<span class='name'>before</span>
|
145
|
+
<span class='arguments'>(&b)</span>
|
146
|
+
</div>
|
147
|
+
<div class='description'>
|
148
|
+
<p>
|
149
|
+
Define a block to be called before the command. This is useful for opening
|
150
|
+
database connections, etc...
|
151
|
+
</p>
|
152
|
+
</div>
|
153
|
+
<div class='source'>
|
154
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000006-source'); return false">
|
155
|
+
[show source]
|
156
|
+
</a>
|
157
|
+
<pre id='M000006-source'> <span class="ruby-comment cmt"># File lib/drydock.rb, line 159</span>
159: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">before</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">b</span>)
160: <span class="ruby-ivar">@@before_block</span> = <span class="ruby-identifier">b</span>
161: <span class="ruby-keyword kw">end</span></pre>
|
158
|
+
</div>
|
159
|
+
</div>
|
160
|
+
<div class='public-instance method' id='method-M000014'>
|
161
|
+
<a name='M000014'> </a>
|
162
|
+
<div class='synopsis'>
|
163
|
+
<span class='name'>command</span>
|
164
|
+
<span class='arguments'>(*cmds, &b)</span>
|
165
|
+
</div>
|
166
|
+
<div class='description'>
|
167
|
+
<p>
|
168
|
+
Define a command.
|
169
|
+
</p>
|
170
|
+
<pre>command :task do
 ...
end</pre>
|
171
|
+
<p>
|
172
|
+
A custom command class can be specified using Hash syntax. The class must
|
173
|
+
inherit from <a href="Drydock/Command.html">Drydock::Command</a> (class
|
174
|
+
CustomeClass < <a href="Drydock/Command.html">Drydock::Command</a>)
|
175
|
+
</p>
|
176
|
+
<pre>command :task => CustomCommand do
 ...
end</pre>
|
177
|
+
</div>
|
178
|
+
<div class='source'>
|
179
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000014-source'); return false">
|
180
|
+
[show source]
|
181
|
+
</a>
|
182
|
+
<pre id='M000014-source'> <span class="ruby-comment cmt"># File lib/drydock.rb, line 244</span>
244: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">command</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">cmds</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">b</span>)
245: <span class="ruby-ivar">@@command_index</span> <span class="ruby-operator">||=</span> <span class="ruby-value">0</span>
246: <span class="ruby-ivar">@@command_opts_parser</span> <span class="ruby-operator">||=</span> []
247: <span class="ruby-ivar">@@command_option_names</span> <span class="ruby-operator">||=</span> []
248: <span class="ruby-identifier">cmds</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">cmd</span><span class="ruby-operator">|</span> 
249: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">cmd</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Hash</span>
250: <span class="ruby-identifier">c</span> = <span class="ruby-identifier">cmd</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">cmd</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">first</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">b</span>)
251: <span class="ruby-keyword kw">else</span>
252: <span class="ruby-identifier">c</span> = <span class="ruby-constant">Drydock</span><span class="ruby-operator">::</span><span class="ruby-constant">Command</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">cmd</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">b</span>)
253: <span class="ruby-keyword kw">end</span>
254: <span class="ruby-identifier">commands</span>[<span class="ruby-identifier">c</span>.<span class="ruby-identifier">cmd</span>] = <span class="ruby-identifier">c</span>
255: <span class="ruby-identifier">command_index_map</span>[<span class="ruby-identifier">c</span>.<span class="ruby-identifier">cmd</span>] = <span class="ruby-ivar">@@command_index</span>
256: <span class="ruby-ivar">@@command_index</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
257: <span class="ruby-keyword kw">end</span>
258: 
259: <span class="ruby-keyword kw">end</span></pre>
|
183
|
+
</div>
|
184
|
+
</div>
|
185
|
+
<div class='public-instance method' id='method-M000016'>
|
186
|
+
<a name='M000016'> </a>
|
187
|
+
<div class='synopsis'>
|
188
|
+
<span class='name'>command_alias</span>
|
189
|
+
<span class='arguments'>(aliaz, cmd)</span>
|
190
|
+
</div>
|
191
|
+
<div class='description'>
|
192
|
+
<p>
|
193
|
+
Alias for <a href="Drydock.html#M000015">alias_command</a>
|
194
|
+
</p>
|
195
|
+
</div>
|
196
|
+
</div>
|
197
|
+
<div class='public-instance method' id='method-M000017'>
|
198
|
+
<a name='M000017'> </a>
|
199
|
+
<div class='synopsis'>
|
200
|
+
<span class='name'>commands</span>
|
201
|
+
<span class='arguments'>()</span>
|
202
|
+
</div>
|
203
|
+
<div class='description'>
|
204
|
+
<p>
|
205
|
+
An array of the currently defined <a
|
206
|
+
href="Drydock/Command.html">Drydock::Command</a> objects
|
207
|
+
</p>
|
208
|
+
</div>
|
209
|
+
<div class='source'>
|
210
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000017-source'); return false">
|
211
|
+
[show source]
|
212
|
+
</a>
|
213
|
+
<pre id='M000017-source'> <span class="ruby-comment cmt"># File lib/drydock.rb, line 281</span>
281: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">commands</span>
282: <span class="ruby-ivar">@@commands</span> <span class="ruby-operator">||=</span> {}
283: <span class="ruby-keyword kw">end</span></pre>
|
214
|
+
</div>
|
215
|
+
</div>
|
216
|
+
<div class='public-instance method' id='method-M000002'>
|
217
|
+
<a name='M000002'> </a>
|
218
|
+
<div class='synopsis'>
|
219
|
+
<span class='name'>debug</span>
|
220
|
+
<span class='arguments'>(toggle=false)</span>
|
221
|
+
</div>
|
222
|
+
<div class='description'>
|
223
|
+
<p>
|
224
|
+
Enable or disable debug output.
|
225
|
+
</p>
|
226
|
+
<pre>debug :on
debug :off</pre>
|
227
|
+
<p>
|
228
|
+
Calling without :on or :off will toggle the value.
|
229
|
+
</p>
|
230
|
+
</div>
|
231
|
+
<div class='source'>
|
232
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000002-source'); return false">
|
233
|
+
[show source]
|
234
|
+
</a>
|
235
|
+
<pre id='M000002-source'> <span class="ruby-comment cmt"># File lib/drydock.rb, line 126</span>
126: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">debug</span>(<span class="ruby-identifier">toggle</span>=<span class="ruby-keyword kw">false</span>)
127: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">toggle</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Symbol</span>
128: <span class="ruby-ivar">@@debug</span> = <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">toggle</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:on</span>
129: <span class="ruby-ivar">@@debug</span> = <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">toggle</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:off</span>
130: <span class="ruby-keyword kw">else</span>
131: <span class="ruby-ivar">@@debug</span> = (<span class="ruby-operator">!</span><span class="ruby-ivar">@@debug</span>)
132: <span class="ruby-keyword kw">end</span>
133: <span class="ruby-keyword kw">end</span></pre>
|
236
|
+
</div>
|
237
|
+
</div>
|
238
|
+
<div class='public-instance method' id='method-M000003'>
|
239
|
+
<a name='M000003'> </a>
|
240
|
+
<div class='synopsis'>
|
241
|
+
<span class='name'>debug?</span>
|
242
|
+
<span class='arguments'>()</span>
|
243
|
+
</div>
|
244
|
+
<div class='description'>
|
245
|
+
<p>
|
246
|
+
Returns true if debug output is enabled.
|
247
|
+
</p>
|
248
|
+
</div>
|
249
|
+
<div class='source'>
|
250
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000003-source'); return false">
|
251
|
+
[show source]
|
252
|
+
</a>
|
253
|
+
<pre id='M000003-source'> <span class="ruby-comment cmt"># File lib/drydock.rb, line 135</span>
135: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">debug?</span>
136: <span class="ruby-ivar">@@debug</span>
137: <span class="ruby-keyword kw">end</span></pre>
|
254
|
+
</div>
|
255
|
+
</div>
|
256
|
+
<div class='public-instance method' id='method-M000004'>
|
257
|
+
<a name='M000004'> </a>
|
258
|
+
<div class='synopsis'>
|
259
|
+
<span class='name'>default</span>
|
260
|
+
<span class='arguments'>(cmd)</span>
|
261
|
+
</div>
|
262
|
+
<div class='description'>
|
263
|
+
<p>
|
264
|
+
Define a default command.
|
265
|
+
</p>
|
266
|
+
<pre>default :task</pre>
|
267
|
+
</div>
|
268
|
+
<div class='source'>
|
269
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000004-source'); return false">
|
270
|
+
[show source]
|
271
|
+
</a>
|
272
|
+
<pre id='M000004-source'> <span class="ruby-comment cmt"># File lib/drydock.rb, line 143</span>
143: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">default</span>(<span class="ruby-identifier">cmd</span>)
144: <span class="ruby-ivar">@@default_command</span> = <span class="ruby-identifier">canonize</span>(<span class="ruby-identifier">cmd</span>)
145: <span class="ruby-keyword kw">end</span></pre>
|
273
|
+
</div>
|
274
|
+
</div>
|
275
|
+
<div class='public-instance method' id='method-M000010'>
|
276
|
+
<a name='M000010'> </a>
|
277
|
+
<div class='synopsis'>
|
278
|
+
<span class='name'>get_current_option_parser</span>
|
279
|
+
<span class='arguments'>()</span>
|
280
|
+
</div>
|
281
|
+
<div class='description'>
|
282
|
+
<p>
|
283
|
+
Grab the options parser for the current command or create it if it
|
284
|
+
doesn’t exist.
|
285
|
+
</p>
|
286
|
+
</div>
|
287
|
+
<div class='source'>
|
288
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000010-source'); return false">
|
289
|
+
[show source]
|
290
|
+
</a>
|
291
|
+
<pre id='M000010-source'> <span class="ruby-comment cmt"># File lib/drydock.rb, line 183</span>
183: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_current_option_parser</span>
184: <span class="ruby-ivar">@@command_opts_parser</span> <span class="ruby-operator">||=</span> []
185: <span class="ruby-ivar">@@command_index</span> <span class="ruby-operator">||=</span> <span class="ruby-value">0</span>
186: (<span class="ruby-ivar">@@command_opts_parser</span>[<span class="ruby-ivar">@@command_index</span>] <span class="ruby-operator">||=</span> <span class="ruby-constant">OptionParser</span>.<span class="ruby-identifier">new</span>)
187: <span class="ruby-keyword kw">end</span></pre>
|
292
|
+
</div>
|
293
|
+
</div>
|
294
|
+
<div class='public-instance method' id='method-M000012'>
|
295
|
+
<a name='M000012'> </a>
|
296
|
+
<div class='synopsis'>
|
297
|
+
<span class='name'>global_option</span>
|
298
|
+
<span class='arguments'>(*args, &b)</span>
|
299
|
+
</div>
|
300
|
+
<div class='description'>
|
301
|
+
<p>
|
302
|
+
Define a global option. See <tt>option</tt> for more info.
|
303
|
+
</p>
|
304
|
+
</div>
|
305
|
+
<div class='source'>
|
306
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000012-source'); return false">
|
307
|
+
[show source]
|
308
|
+
</a>
|
309
|
+
<pre id='M000012-source'> <span class="ruby-comment cmt"># File lib/drydock.rb, line 202</span>
202: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">global_option</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">b</span>)
203: <span class="ruby-identifier">args</span>.<span class="ruby-identifier">unshift</span>(<span class="ruby-identifier">global_opts_parser</span>)
204: <span class="ruby-identifier">global_option_names</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">option_parser</span>(<span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">b</span>)
205: <span class="ruby-keyword kw">end</span></pre>
|
310
|
+
</div>
|
311
|
+
</div>
|
312
|
+
<div class='public-instance method' id='method-M000008'>
|
313
|
+
<a name='M000008'> </a>
|
314
|
+
<div class='synopsis'>
|
315
|
+
<span class='name'>global_usage</span>
|
316
|
+
<span class='arguments'>(msg)</span>
|
317
|
+
</div>
|
318
|
+
<div class='description'>
|
319
|
+
<p>
|
320
|
+
Define the default global usage banner. This is displayed with
|
321
|
+
“script -h”.
|
322
|
+
</p>
|
323
|
+
</div>
|
324
|
+
<div class='source'>
|
325
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000008-source'); return false">
|
326
|
+
[show source]
|
327
|
+
</a>
|
328
|
+
<pre id='M000008-source'> <span class="ruby-comment cmt"># File lib/drydock.rb, line 171</span>
171: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">global_usage</span>(<span class="ruby-identifier">msg</span>)
172: <span class="ruby-ivar">@@global_options</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>
173: <span class="ruby-identifier">global_opts_parser</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-node">"USAGE: #{msg}"</span>
174: <span class="ruby-keyword kw">end</span></pre>
|
329
|
+
</div>
|
330
|
+
</div>
|
331
|
+
<div class='public-instance method' id='method-M000020'>
|
332
|
+
<a name='M000020'> </a>
|
333
|
+
<div class='synopsis'>
|
334
|
+
<span class='name'>has_run?</span>
|
335
|
+
<span class='arguments'>()</span>
|
336
|
+
</div>
|
337
|
+
<div class='description'>
|
338
|
+
<p>
|
339
|
+
Return true if a command has been executed.
|
340
|
+
</p>
|
341
|
+
</div>
|
342
|
+
<div class='source'>
|
343
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000020-source'); return false">
|
344
|
+
[show source]
|
345
|
+
</a>
|
346
|
+
<pre id='M000020-source'> <span class="ruby-comment cmt"># File lib/drydock.rb, line 298</span>
298: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">has_run?</span>
299: <span class="ruby-ivar">@@has_run</span>
300: <span class="ruby-keyword kw">end</span></pre>
|
347
|
+
</div>
|
348
|
+
</div>
|
349
|
+
<div class='public-instance method' id='method-M000011'>
|
350
|
+
<a name='M000011'> </a>
|
351
|
+
<div class='synopsis'>
|
352
|
+
<span class='name'>ignore</span>
|
353
|
+
<span class='arguments'>(what=:nothing)</span>
|
354
|
+
</div>
|
355
|
+
<div class='description'>
|
356
|
+
<p>
|
357
|
+
Tell the <a href="Drydock.html">Drydock</a> parser to ignore something. <a
|
358
|
+
href="Drydock.html">Drydock</a> will currently only listen to you if you
|
359
|
+
tell it to “ignore :options”, otherwise it will ignore you!
|
360
|
+
</p>
|
361
|
+
<p>
|
362
|
+
<tt>what</tt> the thing to ignore. When it equals :options <a
|
363
|
+
href="Drydock.html">Drydock</a> will not parse the command-specific
|
364
|
+
arguments. It will pass the <a href="Drydock/Command.html">Command</a>
|
365
|
+
object the list of arguments. This is useful when you want to parse the
|
366
|
+
arguments in some a way that’s too crazy, dangerous for <a
|
367
|
+
href="Drydock.html">Drydock</a> to handle automatically.
|
368
|
+
</p>
|
369
|
+
</div>
|
370
|
+
<div class='source'>
|
371
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000011-source'); return false">
|
372
|
+
[show source]
|
373
|
+
</a>
|
374
|
+
<pre id='M000011-source'> <span class="ruby-comment cmt"># File lib/drydock.rb, line 197</span>
197: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">ignore</span>(<span class="ruby-identifier">what</span>=<span class="ruby-identifier">:nothing</span>)
198: <span class="ruby-ivar">@@command_opts_parser</span>[<span class="ruby-ivar">@@command_index</span>] = <span class="ruby-identifier">:ignore</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">what</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:options</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">what</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:all</span>
199: <span class="ruby-keyword kw">end</span></pre>
|
375
|
+
</div>
|
376
|
+
</div>
|
377
|
+
<div class='public-instance method' id='method-M000013'>
|
378
|
+
<a name='M000013'> </a>
|
379
|
+
<div class='synopsis'>
|
380
|
+
<span class='name'>option</span>
|
381
|
+
<span class='arguments'>(*args, &b)</span>
|
382
|
+
</div>
|
383
|
+
<div class='description'>
|
384
|
+
<p>
|
385
|
+
Define a command-specific option.
|
386
|
+
</p>
|
387
|
+
<p>
|
388
|
+
<tt>args</tt> is passed directly to OptionParser.on so it can contain
|
389
|
+
anything that’s valid to that method. Some examples: [:h, :help,
|
390
|
+
“Displays this message”] [:m, :max, Integer, “Maximum
|
391
|
+
threshold”] [’-l x,y,z’, ’—lang=x,y,z’,
|
392
|
+
Array, “Requested languages”] If a class is included, it will
|
393
|
+
tell OptionParser to expect a value otherwise it assumes a boolean value.
|
394
|
+
</p>
|
395
|
+
<p>
|
396
|
+
All calls to <tt>option</tt> must come before the command they’re
|
397
|
+
associated to. Example:
|
398
|
+
</p>
|
399
|
+
<pre>option :l, :longname, String, "Description" do; ...; end
command :task do |obj|; ...; end</pre>
|
400
|
+
<p>
|
401
|
+
When calling your script with a specific command-line option, the value is
|
402
|
+
available via obj.longname inside the command block.
|
403
|
+
</p>
|
404
|
+
</div>
|
405
|
+
<div class='source'>
|
406
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000013-source'); return false">
|
407
|
+
[show source]
|
408
|
+
</a>
|
409
|
+
<pre id='M000013-source'> <span class="ruby-comment cmt"># File lib/drydock.rb, line 226</span>
226: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">option</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">b</span>)
227: <span class="ruby-identifier">args</span>.<span class="ruby-identifier">unshift</span>(<span class="ruby-identifier">get_current_option_parser</span>)
228: <span class="ruby-identifier">current_command_option_names</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">option_parser</span>(<span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">b</span>)
229: <span class="ruby-keyword kw">end</span></pre>
|
410
|
+
</div>
|
411
|
+
</div>
|
412
|
+
<div class='public-instance method' id='method-M000021'>
|
413
|
+
<a name='M000021'> </a>
|
414
|
+
<div class='synopsis'>
|
415
|
+
<span class='name'>run!</span>
|
416
|
+
<span class='arguments'>(argv=[], stdin=STDIN)</span>
|
417
|
+
</div>
|
418
|
+
<div class='description'>
|
419
|
+
<p>
|
420
|
+
Execute the given command. By default, <a href="Drydock.html">Drydock</a>
|
421
|
+
automatically executes itself and provides handlers for known errors. You
|
422
|
+
can override this functionality by calling <tt><a
|
423
|
+
href="Drydock.html#M000021">Drydock.run!</a></tt> yourself. <a
|
424
|
+
href="Drydock.html">Drydock</a> will only call <tt>run!</tt> once.
|
425
|
+
</p>
|
426
|
+
</div>
|
427
|
+
<div class='source'>
|
428
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000021-source'); return false">
|
429
|
+
[show source]
|
430
|
+
</a>
|
431
|
+
<pre id='M000021-source'> <span class="ruby-comment cmt"># File lib/drydock.rb, line 306</span>
306: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run!</span>(<span class="ruby-identifier">argv</span>=[], <span class="ruby-identifier">stdin</span>=<span class="ruby-constant">STDIN</span>)
307: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">has_run?</span>
308: <span class="ruby-ivar">@@has_run</span> = <span class="ruby-keyword kw">true</span>
309: <span class="ruby-identifier">raise</span> <span class="ruby-constant">NoCommandsDefined</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">commands</span>
310: <span class="ruby-ivar">@@global_options</span>, <span class="ruby-identifier">cmd_name</span>, <span class="ruby-ivar">@@command_options</span>, <span class="ruby-identifier">argv</span> = <span class="ruby-identifier">process_arguments</span>(<span class="ruby-identifier">argv</span>)
311: 
312: <span class="ruby-identifier">cmd_name</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">default_command</span>
313: 
314: <span class="ruby-identifier">raise</span> <span class="ruby-constant">UnknownCommand</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">cmd_name</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">command?</span>(<span class="ruby-identifier">cmd_name</span>)
315: 
316: <span class="ruby-identifier">stdin</span> = (<span class="ruby-keyword kw">defined?</span> <span class="ruby-ivar">@@stdin_block</span>) <span class="ruby-operator">?</span> <span class="ruby-ivar">@@stdin_block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">stdin</span>, []) <span class="ruby-operator">:</span> <span class="ruby-identifier">stdin</span>
317: <span class="ruby-ivar">@@before_block</span>.<span class="ruby-identifier">call</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">defined?</span> <span class="ruby-ivar">@@before_block</span>
318: 
319: <span class="ruby-identifier">call_command</span>(<span class="ruby-identifier">cmd_name</span>, <span class="ruby-identifier">argv</span>, <span class="ruby-identifier">stdin</span>)
320: 
321: <span class="ruby-ivar">@@after_block</span>.<span class="ruby-identifier">call</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">defined?</span> <span class="ruby-ivar">@@after_block</span>
322: 
323: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">OptionParser</span><span class="ruby-operator">::</span><span class="ruby-constant">InvalidOption</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">ex</span>
324: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Drydock</span><span class="ruby-operator">::</span><span class="ruby-constant">InvalidArgument</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">ex</span>.<span class="ruby-identifier">args</span>)
325: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">OptionParser</span><span class="ruby-operator">::</span><span class="ruby-constant">MissingArgument</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">ex</span>
326: <span class="ruby-identifier">raise</span> <span class="ruby-constant">Drydock</span><span class="ruby-operator">::</span><span class="ruby-constant">MissingArgument</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">ex</span>.<span class="ruby-identifier">args</span>)
327: <span class="ruby-keyword kw">end</span></pre>
|
432
|
+
</div>
|
433
|
+
</div>
|
434
|
+
<div class='public-instance method' id='method-M000019'>
|
435
|
+
<a name='M000019'> </a>
|
436
|
+
<div class='synopsis'>
|
437
|
+
<span class='name'>run=</span>
|
438
|
+
<span class='arguments'>(v)</span>
|
439
|
+
</div>
|
440
|
+
<div class='description'>
|
441
|
+
<p>
|
442
|
+
Disable automatic execution (enabled by default)
|
443
|
+
</p>
|
444
|
+
<pre>Drydock.run = false</pre>
|
445
|
+
</div>
|
446
|
+
<div class='source'>
|
447
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000019-source'); return false">
|
448
|
+
[show source]
|
449
|
+
</a>
|
450
|
+
<pre id='M000019-source'> <span class="ruby-comment cmt"># File lib/drydock.rb, line 293</span>
293: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run=</span>(<span class="ruby-identifier">v</span>)
294: <span class="ruby-ivar">@@run</span> = (<span class="ruby-identifier">v</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>) <span class="ruby-operator">?</span> <span class="ruby-keyword kw">true</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">false</span> 
295: <span class="ruby-keyword kw">end</span></pre>
|
451
|
+
</div>
|
452
|
+
</div>
|
453
|
+
<div class='public-instance method' id='method-M000018'>
|
454
|
+
<a name='M000018'> </a>
|
455
|
+
<div class='synopsis'>
|
456
|
+
<span class='name'>run?</span>
|
457
|
+
<span class='arguments'>()</span>
|
458
|
+
</div>
|
459
|
+
<div class='description'>
|
460
|
+
<p>
|
461
|
+
Returns true if automatic execution is enabled.
|
462
|
+
</p>
|
463
|
+
</div>
|
464
|
+
<div class='source'>
|
465
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000018-source'); return false">
|
466
|
+
[show source]
|
467
|
+
</a>
|
468
|
+
<pre id='M000018-source'> <span class="ruby-comment cmt"># File lib/drydock.rb, line 286</span>
286: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run?</span>
287: <span class="ruby-ivar">@@run</span>
288: <span class="ruby-keyword kw">end</span></pre>
|
469
|
+
</div>
|
470
|
+
</div>
|
471
|
+
<div class='public-instance method' id='method-M000005'>
|
472
|
+
<a name='M000005'> </a>
|
473
|
+
<div class='synopsis'>
|
474
|
+
<span class='name'>stdin</span>
|
475
|
+
<span class='arguments'>(&b)</span>
|
476
|
+
</div>
|
477
|
+
<div class='description'>
|
478
|
+
<p>
|
479
|
+
Define a block for processing STDIN before the command is called. The
|
480
|
+
command block receives the return value of this block in a named argument:
|
481
|
+
</p>
|
482
|
+
<pre>command :task do |obj, argv, stdin|; ...; end</pre>
|
483
|
+
<p>
|
484
|
+
If a stdin block isn’t defined, <tt>stdin</tt> above will be the
|
485
|
+
STDIN IO handle.
|
486
|
+
</p>
|
487
|
+
</div>
|
488
|
+
<div class='source'>
|
489
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000005-source'); return false">
|
490
|
+
[show source]
|
491
|
+
</a>
|
492
|
+
<pre id='M000005-source'> <span class="ruby-comment cmt"># File lib/drydock.rb, line 153</span>
153: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stdin</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">b</span>)
154: <span class="ruby-ivar">@@stdin_block</span> = <span class="ruby-identifier">b</span>
155: <span class="ruby-keyword kw">end</span></pre>
|
493
|
+
</div>
|
494
|
+
</div>
|
495
|
+
<div class='public-instance method' id='method-M000009'>
|
496
|
+
<a name='M000009'> </a>
|
497
|
+
<div class='synopsis'>
|
498
|
+
<span class='name'>usage</span>
|
499
|
+
<span class='arguments'>(msg)</span>
|
500
|
+
</div>
|
501
|
+
<div class='description'>
|
502
|
+
<p>
|
503
|
+
Define a command-specific usage banner. This is displayed with
|
504
|
+
“script command -h“
|
505
|
+
</p>
|
506
|
+
</div>
|
507
|
+
<div class='source'>
|
508
|
+
<a class='source-toggle' href='#' onclick="toggleCode('M000009-source'); return false">
|
509
|
+
[show source]
|
510
|
+
</a>
|
511
|
+
<pre id='M000009-source'> <span class="ruby-comment cmt"># File lib/drydock.rb, line 178</span>
178: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">usage</span>(<span class="ruby-identifier">msg</span>)
179: <span class="ruby-identifier">get_current_option_parser</span>.<span class="ruby-identifier">banner</span> = <span class="ruby-node">"USAGE: #{msg}"</span>
180: <span class="ruby-keyword kw">end</span></pre>
|
512
|
+
</div>
|
513
|
+
</div>
|
514
|
+
</div>
|
515
|
+
</div>
|
516
|
+
</div>
|
517
|
+
</div>
|
518
|
+
<div id='footer-push'></div>
|
519
|
+
</div>
|
520
|
+
<div id='footer'>
|
521
|
+
<a href="http://github.com/mislav/hanna/tree/master"><strong>Hanna</strong> RDoc template</a>
|
522
|
+
<script type='text/javascript'>
|
523
|
+
//<![CDATA[
|
524
|
+
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
525
|
+
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/scr
|
526
|
+
|
527
|
+
try {
|
528
|
+
var pageTracker = _gat._getTracker("UA-4642735-10");
|
529
|
+
pageTracker._trackPageview();
|
530
|
+
} catch(err) {}
|
531
|
+
//]]>
|
532
|
+
</script>
|
533
|
+
</div>
|
534
|
+
</body>
|
535
|
+
</html>
|