Class: Wandbox::CLI::Run

Inherits:
Thor::Group
  • Object
show all
Defined in:
lib/wandbox/cli/run.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



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
# File 'lib/wandbox/cli/run.rb', line 18

def execute
	filenames.each{ |filename|
		return puts "File '#{filename}' not found." unless File.exist? filename
	}
	filename, *filenames_ = filenames

	lang     = options[:lang]     || Wandbox.file2lang(filename)
	compiler = options[:compiler] || Wandbox.lang2compiler(lang)["name"]
	if compiler.nil?
		return puts "No supported language."
	end

# 			puts compiler["display-compile-command"].sub(/prog\..+/, filename)
# 			puts "Running by #{compiler}..."

	code = File.open(filename).read
	param = {}
	param[:codes] = filenames_.map { |filename|
		{ "file" => filename, "code" => File.open(filename).read }
	}
	param[:stdin]  = options[:stdin] || ""
	param[:save]   = options[:save]  || false
	param[:options] = options[:options]

	# String to Symbol from key
	param.merge! Hash[options[:"post-parameter"].map{|k,v| [k.to_sym, v] }] if options[:"post-parameter"]

	puts param if options[:debug]
	result = Wandbox.run compiler, code, param

	progfile = "prog#{File.extname filename}"

	if param[:save]
		puts result["url"]
	end
	puts result if options[:debug]
	puts "#{result["compiler_message"]}#{result["program_message"]}"
	status = result["status"].to_i
	if status != 0
		exit status
	end
end