Class: Rbcli::Scriptwrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/rbcli/scriptwrapping/scriptwrapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, envvars = nil, block = nil) ⇒ Scriptwrapper

Returns a new instance of Scriptwrapper.



19
20
21
22
23
# File 'lib/rbcli/scriptwrapping/scriptwrapper.rb', line 19

def initialize path, envvars = nil, block = nil
	@path = path
	@envvars = envvars || {}
	@block = block
end

Instance Method Details

#execute(params, args, global_opts, config) ⇒ Object



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
# File 'lib/rbcli/scriptwrapping/scriptwrapper.rb', line 25

def execute params, args, global_opts, config
	####
	#### The following code will flatten one level of the hashes into separate variables
	#### It is deprecated in favor of passing along json to be parsed with JQ
	####
	# env_hash = {}
	# {
	# 		'__PARAMS' => params,
	# 		'__ARGS' => args,
	# 		'__GLOBAL' => global_opts,
	# 		'__CONFIG' => config
	# }.each do |name, hsh|
	# 	hsh.each do |k, v|
	# 		env_hash["#{name}_#{k.upcase}"] = v.to_json
	# 	end
	# end
	# env_hash.merge!(@envvars.deep_stringify!) unless @envvars.nil?

	env_hash = {
			'__RBCLI_PARAMS' => params.to_json,
			'__RBCLI_ARGS' => args.to_json,
			'__RBCLI_GLOBAL' => global_opts.to_json,
			'__RBCLI_CONFIG' => config.to_json,
			'__RBCLI_MYVARS' => @envvars.to_json
	}

	if @block
		path = @block.call params, args, global_opts, config
	else
		path = @path
	end

	# IO.popen(env_hash, path) do |io|
	# 	while (line = io.gets) do
	# 		puts line
	# 	end
	# end
	system(env_hash, path)
end