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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/flow-lite/tool.rb', line 4
def self.main( args=ARGV )
options = {}
OptionParser.new do |parser|
parser.on( '-f FILE', '--file FILE', '--flowfile FILE',
'Read FILE as a flowfile.'
) do |file|
options[:flowfile] = file
end
parser.on( '-r NAME', '--require NAME') do |name|
options[:requires] ||= []
options[:requires] << name
end
parser.on( '-d', '--debug') do |debug|
options[:debug] = debug
ENV['DEBUG']='1' puts "[flow] setting >DEBUG< env variable to >#{1}<"
end
end.parse!( args )
if options[:requires]
names = options[:requires]
names.each do |name|
puts "[flow] auto-require >#{name}<..."
require( name )
end
else config_path = "./config.rb"
if File.exist?( config_path )
puts "[flow] auto-require (default) >#{config_path}<..."
require( config_path )
end
end
path = nil
if options[:flowfile]
path = options[:flowfile]
else
path = Flowfile.find_file
if path.nil?
STDERR.puts "!! ERROR - no flowfile found, sorry - looking for: #{Flowfile::NAMES.join(', ')} in (#{Dir.pwd})"
exit 1
end
end
vars = []
args = args.select do |arg|
if arg == '='
STDERR.puts "!! ERROR - empty var (=) in args; sorry - make sure there are NO spaces before ="
exit 1
elsif arg =~ /^[A-Za-z][A-Za-z0-9_]*=/
vars << arg
false else
true
end
end
if args.size > 0
puts "[flow] #{args.size} arg(s):"
pp args
end
if vars.size > 0
puts "[flow] #{vars.size} var(s):"
pp vars
vars.each do |var|
pos = var.index('=') name = var[0..(pos-1)]
value = var[(pos+1)..-1]
if value.empty? puts "[flow] UNSET >#{name}< env variable"
ENV[ name ] = nil
else
puts "[flow] set >#{name}< env variable to >#{value}<"
ENV[ name ] = value
end
end
end
puts "[flow] loading >#{path}<..."
flowfile = Flowfile.load_file( path )
args.each do |arg|
flowfile.run( arg )
end
end
|