mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-25 23:21:29 +03:00
Feature #4082: Add editor support for user inputs in CLI
This commit is contained in:
parent
f4a2d332da
commit
44234b5954
@ -828,39 +828,46 @@ EOT
|
||||
end
|
||||
|
||||
def OpenNebulaHelper.update_template_helper(append, id, resource, path, xpath, update=true)
|
||||
unless path
|
||||
require 'tempfile'
|
||||
if path
|
||||
return File.read(path)
|
||||
elsif append
|
||||
return editor_input()
|
||||
else
|
||||
if update
|
||||
rc = resource.info
|
||||
|
||||
tmp = Tempfile.new(id.to_s)
|
||||
path = tmp.path
|
||||
|
||||
if !append
|
||||
if update
|
||||
rc = resource.info
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
puts rc.message
|
||||
exit -1
|
||||
end
|
||||
if OpenNebula.is_error?(rc)
|
||||
puts rc.message
|
||||
exit -1
|
||||
end
|
||||
|
||||
tmp << resource.template_like_str(xpath)
|
||||
tmp.flush
|
||||
end
|
||||
|
||||
editor_path = ENV["EDITOR"] ? ENV["EDITOR"] : EDITOR_PATH
|
||||
system("#{editor_path} #{path}")
|
||||
return editor_input(resource.template_like_str(xpath))
|
||||
end
|
||||
end
|
||||
|
||||
unless $?.exitstatus == 0
|
||||
puts "Editor not defined"
|
||||
exit -1
|
||||
end
|
||||
def OpenNebulaHelper.editor_input(contents=nil)
|
||||
require 'tempfile'
|
||||
|
||||
tmp.close
|
||||
tmp = Tempfile.new("one_cli")
|
||||
|
||||
if contents
|
||||
tmp << contents
|
||||
tmp.flush
|
||||
end
|
||||
|
||||
str = File.read(path)
|
||||
str
|
||||
editor_path = ENV["EDITOR"] ? ENV["EDITOR"] : EDITOR_PATH
|
||||
system("#{editor_path} #{tmp.path}")
|
||||
|
||||
unless $?.exitstatus == 0
|
||||
puts "Editor not defined"
|
||||
exit -1
|
||||
end
|
||||
|
||||
tmp.close
|
||||
|
||||
str = File.read(tmp.path)
|
||||
return str
|
||||
end
|
||||
|
||||
def self.parse_user_object(user_object)
|
||||
|
@ -118,7 +118,7 @@ EOT
|
||||
|
||||
answers = ""
|
||||
|
||||
puts "There are some parameters that require user input."
|
||||
puts "There are some parameters that require user input. Use the string <<EDITOR>> to launch an editor (e.g. for multi-line inputs)"
|
||||
|
||||
user_inputs.each do |key, val|
|
||||
input_cfg = val.split('|')
|
||||
@ -137,10 +137,16 @@ EOT
|
||||
print " * (#{key}) #{description}: "
|
||||
|
||||
case type
|
||||
when 'text'
|
||||
when 'text', 'text64'
|
||||
answer = STDIN.readline.chop
|
||||
when 'text64'
|
||||
answer = Base64::encode64(STDIN.readline.chop).strip.delete("\n")
|
||||
|
||||
if answer == "<<EDITOR>>"
|
||||
answer = OpenNebulaHelper.editor_input()
|
||||
end
|
||||
|
||||
if type == 'text64'
|
||||
answer = Base64::encode64(answer).strip.delete("\n")
|
||||
end
|
||||
when 'password'
|
||||
answer = OpenNebulaHelper::OneHelper.get_password
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user