【发布时间】:2019-01-29 14:53:20
【问题描述】:
我在其他功能中使用这个简单的功能来进行可重复使用的用户确认:
function read_confirm --description 'Ask the user for confirmation' --argument prompt
if test -z "$prompt"
set prompt "Do you want to continue? [Y/n]: "
end
while true
read -l -P $prompt confirm
switch $confirm
case N n
return 1
case '' Y y
return 0
end
end
end
这在以前的版本中运行良好,但是现在当我安装版本 3.0.0 时,我似乎总是得到状态码 0。
~ read_confirm
Do you want to continue? [Y/n]:
~ echo $status
0
~ read_confirm
Do you want to continue? [Y/n]: y
~ echo $status
0
~ read_confirm
Do you want to continue? [Y/n]: Y
~ echo $status
0
~ read_confirm
Do you want to continue? [Y/n]: n
~ echo $status
0
~ read_confirm
Do you want to continue? [Y/n]: N
~ echo $status
0
~
起初我以为 case 语句不起作用,但是正确读取了用户输入,它没有前导 '\n',它会转到 'N n' 大小写,函数将正确“完成” ,但是“返回 1”总是将状态设置为 0,我不知道为什么。鱼 API 改变了吗?我只是用错了,需要重写吗?
更新: 创建了一个错误报告,因为这是对以前版本的回归 https://github.com/fish-shell/fish-shell/issues/5600
感谢您的帮助, 斯蒂芬
【问题讨论】: