我想构建一个类似于git的git <command> [<param1> ...]的ui。到目前为止,我想到的是:
function git -d "Description"
switch $argv[1]
case branch
git_branch $argv[2]
case reset
git_reset
end
end
function git_branch -d "Description for branch"
do_something $argv[1]
end
function git_reset -d "Description for reset"
do_something_else
end它是有效的,但有几个问题:
git时没有参数它不会打印出命令列表,也不会提取它们的描述。在我看来,我所做的并不是使用fish构建命令行实用程序的“正确”方法。那么,什么是正确的方式呢?
发布于 2014-04-02 21:43:01
您的问题可能是因为您的switch语句没有默认的分支,所以您从未调用过实际的git命令。尝试:
function git -d "Description"
switch $argv[1]
case branch
git_branch $argv[2]
case reset
git_reset
case '*'
command git $argv
end
end为了防止出现零参数的情况,我这样做:
function git -d "Description"
set -q argv[1]
and switch $argv[1]
case branch
git_branch $argv[2]
return
case reset
git_reset
return
end
command git $argv
endhttps://stackoverflow.com/questions/22732714
复制相似问题