142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
# File 'lib/seeing_is_believing/binary/parse_args.rb', line 142
def ParseArgs.help_screen
<<HELP_SCREEN
Usage: seeing_is_believing [options] [filename]
seeing_is_believing is a program and library that will evaluate a Ruby file and capture/display the results.
If no filename is provided, the binary will read the program from standard input.
-l, --start-line n # line number to begin showing results on
-L, --end-line n # line number to stop showing results on
-d, --line-length n # max length of the entire line (only truncates results, not source lines)
-D, --result-length n # max length of the portion after the "#{VALUE_MARKER}"
-n, --number-of-captures n # how many results to capture for a given line
if you had 1 million results on a line, it could take a long time to record
and serialize them, you might limit it to 1000 results as an optimization
-s, --alignment-strategy name # select the alignment strategy:
chunk (DEFAULT) => each chunk of code is at the same alignment
file => the entire file is at the same alignment
line => each line is at its own alignment
-t, --timeout n # timeout limit in seconds when evaluating source file (ex. -t 0.3 or -t 3)
-I, --load-path dir # a dir that should be added to the $LOAD_PATH
-r, --require file # additional files to be required before running the program
-e, --program program # Pass the program to execute as an argument
-K, --encoding encoding # sets file encoding, equivalent to Ruby's -Kx (see `man ruby` for valid values)
-a, --as filename # run the program as if it was the specified filename
-c, --clean # remove annotations from previous runs of seeing_is_believing
-g, --debug # print debugging information (useful if program is fucking up, or if you want to brag)
-x, --xmpfilter-style # annotate marked lines instead of every line
-j, --json # print results in json format (i.e. so another program can consume them)
-i, --inherit-exit-status # exit with the exit status of the program being eval
--shebang ruby-executable # if you want SiB to use some ruby other than the one in the path
-v, --version # print the version (#{VERSION})
-h, --help # this help screen
Examples: A few examples, for a more comprehensive set of examples, check out features/flags.feature
Run the file f.rb
$ echo __FILE__ > f.rb; seeing_is_believing f.rb
__FILE__ #{VALUE_MARKER}"f.rb"
Aligning comments
$ ruby -e 'puts "123\\n4\\n\\n567890"' > f.rb
$ seeing_is_believing f.rb -s line
123 #{VALUE_MARKER}123
4 #{VALUE_MARKER}4
567890 #{VALUE_MARKER}567890
$ seeing_is_believing f.rb -s chunk
123 #{VALUE_MARKER}123
4 #{VALUE_MARKER}4
567890 #{VALUE_MARKER}567890
$ seeing_is_believing f.rb -s file
123 #{VALUE_MARKER}123
4 #{VALUE_MARKER}4
567890 #{VALUE_MARKER}567890
Run against standard input
$ echo '3.times { |i| puts i }' | seeing_is_believing
2.times { |i| puts i } #{VALUE_MARKER}2
#{STDOUT_MARKER}0
#{STDOUT_MARKER}1
Run against a library you're working on by fixing the load path
$ seeing_is_believing -I lib f.rb
Load up some library (can be used in tandem with -I)
$ seeing_is_believing -r pp -e 'pp [[*1..15],[*15..30]]; nil'
pp [[*1..15],[*15..30]]; nil #{VALUE_MARKER}nil
#{STDOUT_MARKER}[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
#{STDOUT_MARKER} [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]]
Only update the lines you've marked
$ ruby -e 'puts "1\\n2 # =>\\n3"' | seeing_is_believing -x
1
2 #{VALUE_MARKER}2
3
Set a timeout (especially useful if running via an editor)
$ seeing_is_believing -e 'loop { sleep 1 }' -t 3
Timeout Error after 3.0 seconds!
Set the encoding to utf-8
$ seeing_is_believing -Ku -e '"⛄ "'
"⛄ " #{VALUE_MARKER}"⛄ "
The exit status will be 1 if the error is displayable inline
$ seeing_is_believing -e 'raise "omg"'; echo $?
raise "omg" #{EXCEPTION_MARKER}RuntimeError: omg
1
The exit status will be 2 if the error is not displayable
$ seeing_is_believing -e 'a='; echo $status
-:1: syntax error, unexpected $end
2
Run with previous output
$ echo "1+1 #{VALUE_MARKER}old-value" | seeing_is_believing
1+1 #{VALUE_MARKER}2
$ echo "1+1 #{VALUE_MARKER}old-value" | seeing_is_believing --clean
1+1
If your Ruby binary is named something else (e.g. ruby2.0)
$ ruby2.0 -S seeing_is_believing --shebang ruby2.0 -e '123'
123 #{VALUE_MARKER}123
HELP_SCREEN
end
|