fish 不会 return 从具有 "return" 的函数中指定状态代码

fish won't return specified status code from function with "return"

我在我的其他功能中使用这个简单的功能来进行可重复使用的用户确认:

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' case,函数会正常"finish",但是 "return 1" 总是将状态设置为 0,我不明白为什么。鱼API变了吗?我只是用错了,需要重写吗?

更新: 创建了一个错误报告,因为这是对以前版本的回归 https://github.com/fish-shell/fish-shell/issues/5600

感谢您的帮助, 斯特凡

这是一个已知错误,将在下一个点版本中修复。参见 https://github.com/fish-shell/fish-shell/issues/5513