如何为命名函数参数设置默认值?

问题描述:

我已经找到答案,并且what I've found似乎不起作用。如果我运行weather "NYC",echo'd行是“weather = NYC”,但是如果我运行weather,echo'd行是“weather =”。我如何设置$location的默认值?如何为命名函数参数设置默认值?

function weather --argument location --description "Display weather information for a given location" 
    set -q location; or set location "San Francisco, CA" 
    echo "weather = $location" 
    curl -H "Accept-Language: en" "wttr.in/$location?u" 
end 

更新:

我已经能够出现以下变化所需的行为,但我仍然感到好奇,如果set -q location; or set location "San Francisco, CA"应该工作。它似乎在命令行上,但不在函数中。

if not test -n "$location" 
    set location "Washington, DC" 
end 

https://github.com/fish-shell/fish-shell/issues/2645

你的解决方法的解腥的是:以上

set -q location[1] 
or set location "Washington, DC" 

在实践解决方案和腥一个等同于简单的测试VAR是否设置。