我正在编写一个需要链接外部脚本的程序。
目前我正在尝试编写一个验证器方法,该方法检查给定目录中是否存在外部脚本;如果没有,则要求最终用户输入包含脚本的目录的完整路径或相对路径。
但是,我想让用户选择退出而不进入目录。
这是我目前正在使用的方法。如果取消注释注释部分,即使 inp.downcase == "quit"... 仍然会引发参数错误
def signalp_validator(signalp_dir)
if File.exist? "#{signalp_dir}/signalp"
signalp_directory = signalp_dir
else
puts # a blank line
puts "Error: The Signal P directory cannot be found in the following location: \"#{signalp_dir}/signalp\"."
begin
puts # a blank line
puts "Please enter the full path or a relative path to the Signal P directory."
print "> "
inp = $stdin.gets.chomp
raise ArgumentError, "Error: The Signal P directory cannot be found in the following location: \"#{inp}/signalp\"." unless File.exist? "#{inp}/signalp" # || inp.downcase == "quit"
rescue Exception => e
puts # a blank line
puts e.message
retry
else
# if inp.downcase == "quit"
# abort "\nError: A output directory is required - please create one and then try again.\n\n"
# else
signalp_directory = inp
end
end
end
return signalp_directory
end
如果我从此更改 RaiseArgument 行(如上面的脚本中所示)
raise ArgumentError, "Error: The Signal P directory cannot be found in the following location: \"#{inp}/signalp\"." unless File.exist? "#{inp}/signalp" || inp.downcase == "quit"
对此,
raise ArgumentError, "Error: The Signal P directory cannot be found in the following location: \"#{inp}/signalp\"." unless inp.downcase == "quit" || File.exist? "#{inp}/signalp"
我收到以下错误
project/np_search/lib/np_search/library.rb:17: syntax error, unexpected tSTRING_BEG, expecting keyword_end (SyntaxError)
...case == "quit" || File.exist? "#{inp}/signalp"
... ^
有谁知道我做错了什么以及如何解决。
非常感激任何的帮助。