caliph 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/Caliph/CommandChain.html +532 -0
- data/doc/Caliph/CommandLine.html +2541 -0
- data/doc/Caliph/CommandLineDSL.html +230 -0
- data/doc/Caliph/CommandLineExampleGroup/MockingExecute.html +174 -0
- data/doc/Caliph/CommandLineExampleGroup.html +366 -0
- data/doc/Caliph/CommandRunResult.html +1124 -0
- data/doc/Caliph/DefineOp/ClassMethods.html +250 -0
- data/doc/Caliph/DefineOp.html +188 -0
- data/doc/Caliph/MockCommandResult.html +465 -0
- data/doc/Caliph/PipelineChain.html +242 -0
- data/doc/Caliph/PrereqChain.html +242 -0
- data/doc/Caliph/ShellEscaped.html +445 -0
- data/doc/Caliph/WrappingChain.html +242 -0
- data/doc/Caliph.html +119 -0
- data/doc/_index.html +241 -0
- data/doc/class_list.html +54 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +57 -0
- data/doc/css/style.css +339 -0
- data/doc/file.README.html +235 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +26 -0
- data/doc/index.html +235 -0
- data/doc/js/app.js +219 -0
- data/doc/js/full_list.js +178 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +503 -0
- data/doc/top-level-namespace.html +112 -0
- data/lib/caliph/command-chain.rb +4 -1
- data/lib/caliph/command-line.rb +24 -81
- data/lib/caliph/command-run-result.rb +48 -7
- data/lib/caliph/shell.rb +172 -0
- data/lib/caliph.rb +9 -0
- data/spec/command-line-dsl.rb +15 -15
- data/spec/command-line.rb +16 -18
- data/spec_help/spec_helper.rb +9 -3
- metadata +63 -6
@@ -0,0 +1,235 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
6
|
+
<title>
|
7
|
+
File: README
|
8
|
+
|
9
|
+
— Documentation by YARD 0.8.7.4
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
hasFrames = window.top.frames.main ? true : false;
|
19
|
+
relpath = '';
|
20
|
+
framesUrl = "frames.html#!file.README.html";
|
21
|
+
</script>
|
22
|
+
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
25
|
+
|
26
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
27
|
+
|
28
|
+
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="header">
|
32
|
+
<div id="menu">
|
33
|
+
|
34
|
+
<a href="_index.html">Index</a> »
|
35
|
+
<span class="title">File: README</span>
|
36
|
+
|
37
|
+
|
38
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div id="search">
|
42
|
+
|
43
|
+
<a class="full_list_link" id="class_list_link"
|
44
|
+
href="class_list.html">
|
45
|
+
Class List
|
46
|
+
</a>
|
47
|
+
|
48
|
+
<a class="full_list_link" id="method_list_link"
|
49
|
+
href="method_list.html">
|
50
|
+
Method List
|
51
|
+
</a>
|
52
|
+
|
53
|
+
<a class="full_list_link" id="file_list_link"
|
54
|
+
href="file_list.html">
|
55
|
+
File List
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<iframe id="search_frame"></iframe>
|
63
|
+
|
64
|
+
<div id="content"><div id='filecontents'>
|
65
|
+
<h1 id="label-Caliph">Caliph</h1>
|
66
|
+
|
67
|
+
<p>Caliph - a Ruby tool for generating and executing command-line commands.</p>
|
68
|
+
|
69
|
+
<p>Does your Ruby script or app need to generate commands to run at the CLI,
|
70
|
+
to run with system() or similar? Want to generate them in a clean, testable
|
71
|
+
Ruby api? How about automatically capturing output, exit code, and other
|
72
|
+
goodies?</p>
|
73
|
+
|
74
|
+
<p>The first version of these classes were originally written as part of
|
75
|
+
Mattock by Judson Lester: <a
|
76
|
+
href="https://github.com/nyarly/mattock">github.com/nyarly/mattock</a></p>
|
77
|
+
|
78
|
+
<p><a href="https://codeclimate.com/github/LRDesign/Caliph"><img
|
79
|
+
src="https://codeclimate.com/github/LRDesign/Caliph.png"></a> <a
|
80
|
+
href="https://travis-ci.org/LRDesign/Caliph"><img
|
81
|
+
src="https://travis-ci.org/LRDesign/Caliph.svg?branch=master"></a> <a
|
82
|
+
href="https://gemnasium.com/LRDesign/Caliph"><img
|
83
|
+
src="https://gemnasium.com/LRDesign/Caliph.svg"></a></p>
|
84
|
+
|
85
|
+
<h2 id="label-Usage+Examples">Usage Examples</h2>
|
86
|
+
|
87
|
+
<h3 id="label-Create+a+command">Create a command</h3>
|
88
|
+
|
89
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># 'ls -la'
|
90
|
+
</span> <span class='const'>Caliph</span><span class='op'>::</span><span class='const'>CommandLine</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ls</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>-la</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
91
|
+
|
92
|
+
<span class='comment'># 'ls -la', another way
|
93
|
+
</span> <span class='id identifier rubyid_cmd'>cmd</span> <span class='op'>=</span> <span class='const'>Caliph</span><span class='op'>::</span><span class='const'>CommandLine</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ls</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
94
|
+
<span class='id identifier rubyid_cmd'>cmd</span><span class='period'>.</span><span class='id identifier rubyid_options'>options</span> <span class='op'><<</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>-la</span><span class='tstring_end'>'</span></span></code></pre>
|
95
|
+
|
96
|
+
<h3 id="label-Mix+in+Caliph%3A%3ACommandLineDSL+for+abbreviated+syntax">Mix in Caliph::CommandLineDSL for abbreviated syntax</h3>
|
97
|
+
|
98
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_include'>include</span> <span class='const'>Caliph</span><span class='op'>::</span><span class='const'>CommandLineDSL</span>
|
99
|
+
|
100
|
+
<span class='comment'># synonymous with Caliph::CommandLine.new('cat', '/etc/passwd')
|
101
|
+
</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>cat</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>/etc/passwd</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span></code></pre>
|
102
|
+
|
103
|
+
<h3 id="label-Add+environment+variables">Add environment variables</h3>
|
104
|
+
|
105
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># RAILS_ENV=production rake db:migrate
|
106
|
+
</span> <span class='id identifier rubyid_command'>command</span> <span class='op'>=</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>rake</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>db:migrate</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
107
|
+
<span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_env'>env</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>RAILS_ENV</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_end'>production</span></span></code></pre>
|
108
|
+
|
109
|
+
<h3 id="label-See+the+commands">See the commands</h3>
|
110
|
+
|
111
|
+
<p><code>Caliph::CommandLine#string_format</code> or <code>#to_s</code>
|
112
|
+
returns the entire command. <code>Caliph::CommandLine#command</code>
|
113
|
+
returns just the command portion without prepended environment variables,
|
114
|
+
which might be handy if you're passing the command to ssh or sudo and
|
115
|
+
need to handle ENV differently.</p>
|
116
|
+
|
117
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_command'>command</span> <span class='op'>=</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>java</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>my_file.jar</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
118
|
+
<span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_env'>env</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>JAVA_HOME</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>~/java_files</span><span class='tstring_end'>'</span></span>
|
119
|
+
|
120
|
+
<span class='comment'># outputs "JAVA_HOME='~/java_files' java my_file.jar"
|
121
|
+
</span> <span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_string_format'>string_format</span> <span class='comment'># or .to_s
|
122
|
+
</span>
|
123
|
+
<span class='comment'># outputs "java my_file.jar"
|
124
|
+
</span> <span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_command'>command</span></code></pre>
|
125
|
+
|
126
|
+
<h3 id="label-Chaining+commands">Chaining commands</h3>
|
127
|
+
|
128
|
+
<p><code>Caliph::CommandChain</code> and related classes implement chained
|
129
|
+
commands. If you've mixed in <code>Caliph::CommandLineDSL</code>, you
|
130
|
+
can use operators &, |, and - for conditional, pipe, and path-chaining,
|
131
|
+
respectively.</p>
|
132
|
+
|
133
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># Pipe Chain
|
134
|
+
</span> <span class='comment'># find . -name '*.sw.' | xargs rm
|
135
|
+
</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>find</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>.</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>-name '*.sw.'</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>|</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>xargs</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>rm</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
136
|
+
|
137
|
+
|
138
|
+
<span class='comment'># && - style conditional chain
|
139
|
+
</span> <span class='comment'># cd /tmp/trash && rm -rf *
|
140
|
+
</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>cd</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/tmp/trash</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>&</span> <span class='qwords_beg'>%w{</span><span class='tstring_content'>rm</span><span class='words_sep'> </span><span class='tstring_content'>-rf</span><span class='words_sep'> </span><span class='tstring_content'>*</span><span class='words_sep'>}</span>
|
141
|
+
|
142
|
+
<span class='comment'># Double-hyphen separated commands
|
143
|
+
</span> <span class='comment'># sudo -- gem install bundler
|
144
|
+
</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>sudo</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>-</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>gem</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>install</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>bundler</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span></code></pre>
|
145
|
+
|
146
|
+
<h3 id="label-Redirecting+Output">Redirecting Output</h3>
|
147
|
+
|
148
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># redirect STDOUT
|
149
|
+
</span> <span class='comment'># echo "foo" 1>some_file.txt
|
150
|
+
</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>echo</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_redirect_stdout'>redirect_stdout</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>some_file.txt</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
151
|
+
|
152
|
+
<span class='comment'># redirect STDERR
|
153
|
+
</span> <span class='comment'># echo "foo" 2>error_file.txt
|
154
|
+
</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>echo</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_redirect_stderr'>redirect_stderr</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>error_file.txt</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
155
|
+
|
156
|
+
<span class='comment'># chain redirects
|
157
|
+
</span> <span class='comment'># curl http://LRDesign.com 1>page.html 2>progress.txt
|
158
|
+
</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>curl</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>http://LRDesign.com</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_redirect_stdout'>redirect_stdout</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>page.html</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_redirect_stdin'>redirect_stdin</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>progress.txt</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
159
|
+
|
160
|
+
<span class='comment'># redirect STDOUT and STDERR to the same destination with one command
|
161
|
+
</span> <span class='comment'># rm -rf 1>/dev/null 2>/dev/null
|
162
|
+
</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>rm</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>-rf</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_redirect_both'>redirect_both</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>/dev/null</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span></code></pre>
|
163
|
+
|
164
|
+
<h3 id="label-Execute+commands+and+capture+the+output">Execute commands and capture the output</h3>
|
165
|
+
|
166
|
+
<p>Several instance methods on <code>CommandLine</code> and
|
167
|
+
<code>CommandChain</code> are provided for executing commands.</p>
|
168
|
+
<ul><li>
|
169
|
+
<p><code>run</code> Run the command and wait for the result. Returns a
|
170
|
+
<code>CommandRunResult</code> instance.</p>
|
171
|
+
</li><li>
|
172
|
+
<p><code>execute</code> Same as <code>run</code>, but terser, with no
|
173
|
+
additional output added to STDOUT.</p>
|
174
|
+
</li><li>
|
175
|
+
<p><code>run_as_replacement</code> Run the command in a new process and kill
|
176
|
+
this process.</p>
|
177
|
+
</li><li>
|
178
|
+
<p><code>run_detached</code> Run the command as a new background process. It
|
179
|
+
can continue even if the caller terminates.</p>
|
180
|
+
</li><li>
|
181
|
+
<p><code>run_in_background</code> Run the command as a background process, but
|
182
|
+
kill it if the caller terminates</p>
|
183
|
+
</li></ul>
|
184
|
+
|
185
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># find all vim swap files and wait for result
|
186
|
+
</span> <span class='id identifier rubyid_results'>results</span> <span class='op'>=</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>find</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>.</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>-name *.sw.'</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_run'>run</span>
|
187
|
+
|
188
|
+
<span class='comment'># delete all vim swap files in a parallel process
|
189
|
+
</span> <span class='id identifier rubyid_command'>command</span> <span class='op'>=</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>find</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>.</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>-name '*.sw.'</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>|</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>xargs</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>rm</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
190
|
+
<span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_run_in_background'>run_in_background</span>
|
191
|
+
|
192
|
+
<span class='comment'># launch a server, terminating this process. Useful for wrapper scripts!
|
193
|
+
</span> <span class='id identifier rubyid_launcher'>launcher</span> <span class='op'>=</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>pg_ctl</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>start -l</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>logfile</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
194
|
+
<span class='id identifier rubyid_launcher'>launcher</span><span class='period'>.</span><span class='id identifier rubyid_run_as_replacement'>run_as_replacement</span></code></pre>
|
195
|
+
|
196
|
+
<h3 id="label-Examine+the+results+of+a+command">Examine the results of a command</h3>
|
197
|
+
|
198
|
+
<p><code>Caliph::CommandLine#execute</code> returns a
|
199
|
+
<code>Caliph::CommandRunResult</code> instance.
|
200
|
+
<code>CommandRunResult</code> has the following useful instance methods:</p>
|
201
|
+
<ul><li>
|
202
|
+
<p><code>stdout</code> A String containing the contents of STDOUT.</p>
|
203
|
+
</li><li>
|
204
|
+
<p><code>stderr</code> A String containing the contents of STDERR.</p>
|
205
|
+
</li><li>
|
206
|
+
<p><code>exit_code</code> The exit code of the command</p>
|
207
|
+
</li><li>
|
208
|
+
<p><code>succeded?</code> True if <code>exit_code</code> is 0.</p>
|
209
|
+
</li><li>
|
210
|
+
<p><code>must_succeed!</code> Calls <code>fail</code> with an error message if
|
211
|
+
the command did not exit successfully.</p>
|
212
|
+
</li></ul>
|
213
|
+
|
214
|
+
<h2 id="label-Testing+code+that+uses+Caliph">Testing code that uses Caliph</h2>
|
215
|
+
|
216
|
+
<p>Caliph includes some useful classes for mocking out the command line
|
217
|
+
environment for purposes of testing. See
|
218
|
+
<code>Caliph::MockCommandResult</code> and <code>Caliph::CommandLine</code>
|
219
|
+
in lib/caliph/testing for more info.</p>
|
220
|
+
|
221
|
+
<p>Further documentation on testing coming soon!</p>
|
222
|
+
|
223
|
+
<h2 id="label-Credits">Credits</h2>
|
224
|
+
|
225
|
+
<p>Evan Dorn and Judson Lester of Logical Reality Design, Inc.</p>
|
226
|
+
</div></div>
|
227
|
+
|
228
|
+
<div id="footer">
|
229
|
+
Generated on Fri Jun 13 17:31:07 2014 by
|
230
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
231
|
+
0.8.7.4 (ruby-2.0.0).
|
232
|
+
</div>
|
233
|
+
|
234
|
+
</body>
|
235
|
+
</html>
|
data/doc/file_list.html
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
|
7
|
+
<link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" charset="utf-8" />
|
8
|
+
|
9
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
14
|
+
|
15
|
+
<script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
|
16
|
+
|
17
|
+
|
18
|
+
<title>File List</title>
|
19
|
+
<base id="base_target" target="_parent" />
|
20
|
+
</head>
|
21
|
+
<body>
|
22
|
+
<script type="text/javascript" charset="utf-8">
|
23
|
+
if (window.top.frames.main) {
|
24
|
+
document.getElementById('base_target').target = 'main';
|
25
|
+
document.body.className = 'frames';
|
26
|
+
}
|
27
|
+
</script>
|
28
|
+
<div id="content">
|
29
|
+
<h1 id="full_list_header">File List</h1>
|
30
|
+
<div id="nav">
|
31
|
+
|
32
|
+
<span><a target="_self" href="class_list.html">
|
33
|
+
Classes
|
34
|
+
</a></span>
|
35
|
+
|
36
|
+
<span><a target="_self" href="method_list.html">
|
37
|
+
Methods
|
38
|
+
</a></span>
|
39
|
+
|
40
|
+
<span><a target="_self" href="file_list.html">
|
41
|
+
Files
|
42
|
+
</a></span>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
<div id="search">Search: <input type="text" /></div>
|
46
|
+
|
47
|
+
<ul id="full_list" class="file">
|
48
|
+
|
49
|
+
|
50
|
+
<li class="r1"><span class="object_link"><a href="index.html" title="README">README</a></a></li>
|
51
|
+
|
52
|
+
|
53
|
+
</ul>
|
54
|
+
</div>
|
55
|
+
</body>
|
56
|
+
</html>
|
data/doc/frames.html
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
7
|
+
<title>Documentation by YARD 0.8.7.4</title>
|
8
|
+
</head>
|
9
|
+
<script type="text/javascript" charset="utf-8">
|
10
|
+
window.onload = function() {
|
11
|
+
var match = unescape(window.location.hash).match(/^#!(.+)/);
|
12
|
+
var name = match ? match[1] : 'index.html';
|
13
|
+
name = name.replace(/^(\w+):\/\//, '').replace(/^\/\//, '');
|
14
|
+
document.writeln('<frameset cols="20%,*">' +
|
15
|
+
'<frame name="list" src="class_list.html" />' +
|
16
|
+
'<frame name="main" src="' + escape(name) + '" />' +
|
17
|
+
'</frameset>');
|
18
|
+
}
|
19
|
+
</script>
|
20
|
+
<noscript>
|
21
|
+
<frameset cols="20%,*">
|
22
|
+
<frame name="list" src="class_list.html" />
|
23
|
+
<frame name="main" src="index.html" />
|
24
|
+
</frameset>
|
25
|
+
</noscript>
|
26
|
+
</html>
|
data/doc/index.html
ADDED
@@ -0,0 +1,235 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
6
|
+
<title>
|
7
|
+
File: README
|
8
|
+
|
9
|
+
— Documentation by YARD 0.8.7.4
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
hasFrames = window.top.frames.main ? true : false;
|
19
|
+
relpath = '';
|
20
|
+
framesUrl = "frames.html#!file.README.html";
|
21
|
+
</script>
|
22
|
+
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
25
|
+
|
26
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
27
|
+
|
28
|
+
|
29
|
+
</head>
|
30
|
+
<body>
|
31
|
+
<div id="header">
|
32
|
+
<div id="menu">
|
33
|
+
|
34
|
+
<a href="_index.html">Index</a> »
|
35
|
+
<span class="title">File: README</span>
|
36
|
+
|
37
|
+
|
38
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div id="search">
|
42
|
+
|
43
|
+
<a class="full_list_link" id="class_list_link"
|
44
|
+
href="class_list.html">
|
45
|
+
Class List
|
46
|
+
</a>
|
47
|
+
|
48
|
+
<a class="full_list_link" id="method_list_link"
|
49
|
+
href="method_list.html">
|
50
|
+
Method List
|
51
|
+
</a>
|
52
|
+
|
53
|
+
<a class="full_list_link" id="file_list_link"
|
54
|
+
href="file_list.html">
|
55
|
+
File List
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<iframe id="search_frame"></iframe>
|
63
|
+
|
64
|
+
<div id="content"><div id='filecontents'>
|
65
|
+
<h1 id="label-Caliph">Caliph</h1>
|
66
|
+
|
67
|
+
<p>Caliph - a Ruby tool for generating and executing command-line commands.</p>
|
68
|
+
|
69
|
+
<p>Does your Ruby script or app need to generate commands to run at the CLI,
|
70
|
+
to run with system() or similar? Want to generate them in a clean, testable
|
71
|
+
Ruby api? How about automatically capturing output, exit code, and other
|
72
|
+
goodies?</p>
|
73
|
+
|
74
|
+
<p>The first version of these classes were originally written as part of
|
75
|
+
Mattock by Judson Lester: <a
|
76
|
+
href="https://github.com/nyarly/mattock">github.com/nyarly/mattock</a></p>
|
77
|
+
|
78
|
+
<p><a href="https://codeclimate.com/github/LRDesign/Caliph"><img
|
79
|
+
src="https://codeclimate.com/github/LRDesign/Caliph.png"></a> <a
|
80
|
+
href="https://travis-ci.org/LRDesign/Caliph"><img
|
81
|
+
src="https://travis-ci.org/LRDesign/Caliph.svg?branch=master"></a> <a
|
82
|
+
href="https://gemnasium.com/LRDesign/Caliph"><img
|
83
|
+
src="https://gemnasium.com/LRDesign/Caliph.svg"></a></p>
|
84
|
+
|
85
|
+
<h2 id="label-Usage+Examples">Usage Examples</h2>
|
86
|
+
|
87
|
+
<h3 id="label-Create+a+command">Create a command</h3>
|
88
|
+
|
89
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># 'ls -la'
|
90
|
+
</span> <span class='const'>Caliph</span><span class='op'>::</span><span class='const'>CommandLine</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ls</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>-la</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
91
|
+
|
92
|
+
<span class='comment'># 'ls -la', another way
|
93
|
+
</span> <span class='id identifier rubyid_cmd'>cmd</span> <span class='op'>=</span> <span class='const'>Caliph</span><span class='op'>::</span><span class='const'>CommandLine</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ls</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
94
|
+
<span class='id identifier rubyid_cmd'>cmd</span><span class='period'>.</span><span class='id identifier rubyid_options'>options</span> <span class='op'><<</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>-la</span><span class='tstring_end'>'</span></span></code></pre>
|
95
|
+
|
96
|
+
<h3 id="label-Mix+in+Caliph%3A%3ACommandLineDSL+for+abbreviated+syntax">Mix in Caliph::CommandLineDSL for abbreviated syntax</h3>
|
97
|
+
|
98
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_include'>include</span> <span class='const'>Caliph</span><span class='op'>::</span><span class='const'>CommandLineDSL</span>
|
99
|
+
|
100
|
+
<span class='comment'># synonymous with Caliph::CommandLine.new('cat', '/etc/passwd')
|
101
|
+
</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>cat</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>/etc/passwd</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span></code></pre>
|
102
|
+
|
103
|
+
<h3 id="label-Add+environment+variables">Add environment variables</h3>
|
104
|
+
|
105
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># RAILS_ENV=production rake db:migrate
|
106
|
+
</span> <span class='id identifier rubyid_command'>command</span> <span class='op'>=</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>rake</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>db:migrate</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
107
|
+
<span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_env'>env</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>RAILS_ENV</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_end'>production</span></span></code></pre>
|
108
|
+
|
109
|
+
<h3 id="label-See+the+commands">See the commands</h3>
|
110
|
+
|
111
|
+
<p><code>Caliph::CommandLine#string_format</code> or <code>#to_s</code>
|
112
|
+
returns the entire command. <code>Caliph::CommandLine#command</code>
|
113
|
+
returns just the command portion without prepended environment variables,
|
114
|
+
which might be handy if you're passing the command to ssh or sudo and
|
115
|
+
need to handle ENV differently.</p>
|
116
|
+
|
117
|
+
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_command'>command</span> <span class='op'>=</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>java</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>my_file.jar</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
118
|
+
<span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_env'>env</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>JAVA_HOME</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>~/java_files</span><span class='tstring_end'>'</span></span>
|
119
|
+
|
120
|
+
<span class='comment'># outputs "JAVA_HOME='~/java_files' java my_file.jar"
|
121
|
+
</span> <span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_string_format'>string_format</span> <span class='comment'># or .to_s
|
122
|
+
</span>
|
123
|
+
<span class='comment'># outputs "java my_file.jar"
|
124
|
+
</span> <span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_command'>command</span></code></pre>
|
125
|
+
|
126
|
+
<h3 id="label-Chaining+commands">Chaining commands</h3>
|
127
|
+
|
128
|
+
<p><code>Caliph::CommandChain</code> and related classes implement chained
|
129
|
+
commands. If you've mixed in <code>Caliph::CommandLineDSL</code>, you
|
130
|
+
can use operators &, |, and - for conditional, pipe, and path-chaining,
|
131
|
+
respectively.</p>
|
132
|
+
|
133
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># Pipe Chain
|
134
|
+
</span> <span class='comment'># find . -name '*.sw.' | xargs rm
|
135
|
+
</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>find</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>.</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>-name '*.sw.'</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>|</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>xargs</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>rm</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
136
|
+
|
137
|
+
|
138
|
+
<span class='comment'># && - style conditional chain
|
139
|
+
</span> <span class='comment'># cd /tmp/trash && rm -rf *
|
140
|
+
</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>cd</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>/tmp/trash</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>&</span> <span class='qwords_beg'>%w{</span><span class='tstring_content'>rm</span><span class='words_sep'> </span><span class='tstring_content'>-rf</span><span class='words_sep'> </span><span class='tstring_content'>*</span><span class='words_sep'>}</span>
|
141
|
+
|
142
|
+
<span class='comment'># Double-hyphen separated commands
|
143
|
+
</span> <span class='comment'># sudo -- gem install bundler
|
144
|
+
</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>sudo</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>-</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>gem</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>install</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>bundler</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span></code></pre>
|
145
|
+
|
146
|
+
<h3 id="label-Redirecting+Output">Redirecting Output</h3>
|
147
|
+
|
148
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># redirect STDOUT
|
149
|
+
</span> <span class='comment'># echo "foo" 1>some_file.txt
|
150
|
+
</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>echo</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_redirect_stdout'>redirect_stdout</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>some_file.txt</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
151
|
+
|
152
|
+
<span class='comment'># redirect STDERR
|
153
|
+
</span> <span class='comment'># echo "foo" 2>error_file.txt
|
154
|
+
</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>echo</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_redirect_stderr'>redirect_stderr</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>error_file.txt</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
155
|
+
|
156
|
+
<span class='comment'># chain redirects
|
157
|
+
</span> <span class='comment'># curl http://LRDesign.com 1>page.html 2>progress.txt
|
158
|
+
</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>curl</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>http://LRDesign.com</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_redirect_stdout'>redirect_stdout</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>page.html</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_redirect_stdin'>redirect_stdin</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>progress.txt</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
159
|
+
|
160
|
+
<span class='comment'># redirect STDOUT and STDERR to the same destination with one command
|
161
|
+
</span> <span class='comment'># rm -rf 1>/dev/null 2>/dev/null
|
162
|
+
</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>rm</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>-rf</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_redirect_both'>redirect_both</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>/dev/null</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span></code></pre>
|
163
|
+
|
164
|
+
<h3 id="label-Execute+commands+and+capture+the+output">Execute commands and capture the output</h3>
|
165
|
+
|
166
|
+
<p>Several instance methods on <code>CommandLine</code> and
|
167
|
+
<code>CommandChain</code> are provided for executing commands.</p>
|
168
|
+
<ul><li>
|
169
|
+
<p><code>run</code> Run the command and wait for the result. Returns a
|
170
|
+
<code>CommandRunResult</code> instance.</p>
|
171
|
+
</li><li>
|
172
|
+
<p><code>execute</code> Same as <code>run</code>, but terser, with no
|
173
|
+
additional output added to STDOUT.</p>
|
174
|
+
</li><li>
|
175
|
+
<p><code>run_as_replacement</code> Run the command in a new process and kill
|
176
|
+
this process.</p>
|
177
|
+
</li><li>
|
178
|
+
<p><code>run_detached</code> Run the command as a new background process. It
|
179
|
+
can continue even if the caller terminates.</p>
|
180
|
+
</li><li>
|
181
|
+
<p><code>run_in_background</code> Run the command as a background process, but
|
182
|
+
kill it if the caller terminates</p>
|
183
|
+
</li></ul>
|
184
|
+
|
185
|
+
<pre class="code ruby"><code class="ruby"><span class='comment'># find all vim swap files and wait for result
|
186
|
+
</span> <span class='id identifier rubyid_results'>results</span> <span class='op'>=</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>find</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>.</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>-name *.sw.'</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_run'>run</span>
|
187
|
+
|
188
|
+
<span class='comment'># delete all vim swap files in a parallel process
|
189
|
+
</span> <span class='id identifier rubyid_command'>command</span> <span class='op'>=</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>find</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>.</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>-name '*.sw.'</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>|</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>xargs</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>rm</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
190
|
+
<span class='id identifier rubyid_command'>command</span><span class='period'>.</span><span class='id identifier rubyid_run_in_background'>run_in_background</span>
|
191
|
+
|
192
|
+
<span class='comment'># launch a server, terminating this process. Useful for wrapper scripts!
|
193
|
+
</span> <span class='id identifier rubyid_launcher'>launcher</span> <span class='op'>=</span> <span class='id identifier rubyid_cmd'>cmd</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>pg_ctl</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>start -l</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>logfile</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
194
|
+
<span class='id identifier rubyid_launcher'>launcher</span><span class='period'>.</span><span class='id identifier rubyid_run_as_replacement'>run_as_replacement</span></code></pre>
|
195
|
+
|
196
|
+
<h3 id="label-Examine+the+results+of+a+command">Examine the results of a command</h3>
|
197
|
+
|
198
|
+
<p><code>Caliph::CommandLine#execute</code> returns a
|
199
|
+
<code>Caliph::CommandRunResult</code> instance.
|
200
|
+
<code>CommandRunResult</code> has the following useful instance methods:</p>
|
201
|
+
<ul><li>
|
202
|
+
<p><code>stdout</code> A String containing the contents of STDOUT.</p>
|
203
|
+
</li><li>
|
204
|
+
<p><code>stderr</code> A String containing the contents of STDERR.</p>
|
205
|
+
</li><li>
|
206
|
+
<p><code>exit_code</code> The exit code of the command</p>
|
207
|
+
</li><li>
|
208
|
+
<p><code>succeded?</code> True if <code>exit_code</code> is 0.</p>
|
209
|
+
</li><li>
|
210
|
+
<p><code>must_succeed!</code> Calls <code>fail</code> with an error message if
|
211
|
+
the command did not exit successfully.</p>
|
212
|
+
</li></ul>
|
213
|
+
|
214
|
+
<h2 id="label-Testing+code+that+uses+Caliph">Testing code that uses Caliph</h2>
|
215
|
+
|
216
|
+
<p>Caliph includes some useful classes for mocking out the command line
|
217
|
+
environment for purposes of testing. See
|
218
|
+
<code>Caliph::MockCommandResult</code> and <code>Caliph::CommandLine</code>
|
219
|
+
in lib/caliph/testing for more info.</p>
|
220
|
+
|
221
|
+
<p>Further documentation on testing coming soon!</p>
|
222
|
+
|
223
|
+
<h2 id="label-Credits">Credits</h2>
|
224
|
+
|
225
|
+
<p>Evan Dorn and Judson Lester of Logical Reality Design, Inc.</p>
|
226
|
+
</div></div>
|
227
|
+
|
228
|
+
<div id="footer">
|
229
|
+
Generated on Fri Jun 13 17:31:07 2014 by
|
230
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
231
|
+
0.8.7.4 (ruby-2.0.0).
|
232
|
+
</div>
|
233
|
+
|
234
|
+
</body>
|
235
|
+
</html>
|