forked from craigp/djinn
/
file_djinn.rb
62 lines (52 loc) · 1.25 KB
/
file_djinn.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env ruby
# $:.unshift(File.join(File.dirname(__FILE__), "../lib"))
require 'rubygems'
require 'djinn'
class FileDjinn
include Djinn
djinn do
configure do
add :output_file do
short_switch "-o"
long_switch "--output-file"
description "File to output stuff to"
required true
end
add_flag :create_file do
short_switch "-c"
long_switch "--create-file"
description "Create output file if it doesn't exist"
end
end
start do
@file = unless File.exists?(config[:output_file])
unless config[:create_file]
log "File not found: #{config[:output_file]}"
nil
else
File.open(config[:output_file], 'a')
end
else
File.open(config[:output_file], 'a')
end
if @file
log "Opening output file: #{File.expand_path(@file.path)}"
loop do
@file.puts "Writing to the file at #{Time.now}"
@file.flush
sleep(5)
end
end
end
exit do
if @file
log "Closing output file.."
@file.close
end
end
end
end
FileDjinn.djinnify do |djinn|
puts "omfg, a djinn"
puts djinn.config.inspect
end