Gle*_* Ma 1 command-line-interface fish rust
问题描述:
我为wsl编写了一个CLI工具来学习rust。它可以使用Windows的explorer.exe打开文件。我称之为“op”。
问题是每次我打开一个新的 wsl 并在 Fish shell 中输入“op”,并使用“Tab”来完成时,都会引发错误:
> op error: the directory does not exist
Oops: command not found
- (line 1):
Oops "./completion"
^~~^
from sourcing file -
called on line 1 of file /usr/share/fish/completions/op.fish
from sourcing file /usr/share/fish/completions/op.fish
Run Code Online (Sandbox Code Playgroud)
(文本“op”是彩色的,其他是白色的)
/usr/share/fish/completions/op.fish:
op completion fish | source
Run Code Online (Sandbox Code Playgroud)
它似乎与fish shell(3.6.0)有关(bash没有错误,因为没有完成)。但这个错误只发生一次,之后命令“op”就会像预期的那样有意义。
我有一个跟随这本书的“minigrep” 。它运行完美,没有错误。
源代码(main.rs):
> op error: the directory does not exist
Oops: command not found
- (line 1):
Oops "./completion"
^~~^
from sourcing file -
called on line 1 of file /usr/share/fish/completions/op.fish
from sourcing file /usr/share/fish/completions/op.fish
Run Code Online (Sandbox Code Playgroud)
预期行为:
输入“op”并使用“Tab”完成将不会引发错误。
更新及解决方案
感谢@faho,这个bug的来源(与rust源代码无关)描述如下:
不知何故,在 /usr/share/fish/completions 中有一个完成鱼脚本 op.fish (通常由同名软件生成。)。但我的“op”不会生成它,因此这个 op.fish 与我的“op”完成发生冲突。
有两种简单的方法可以修复它:
重命名“op”(不是通过别名,而是通过重建)。
将一个空文件写入 ~/.config/fish/completions/op.fish 以便 Fish 加载它而不是 /usr/share/fish/completions/op.fish。
我已经使用了第二种方式,“op”现在效果很好!
您的代码有调试打印:
https://github.com/GlekoMa/op/blob/7ae843acbd37a3f64b162aaf4b984094c7be0aa8/src/main.rs#L17
Run Code Online (Sandbox Code Playgroud)println!("Oops {:?}", path); // This code is for debug.
这将打印Oops ...,因此 Fish 会,因为您告诉它source输出,尝试将其作为命令运行,并且命令“Oops”将不存在,因此它将打印错误。
这种情况只会在完成加载时发生,鱼通常会在您第一次尝试完成某件事时执行此操作。
删除该调试语句,在生成补全时不要打印它(即您获得子命令completion),而是将其打印到 stderr (这意味着它将在加载补全时显示!)或在其前面加上前缀以//使其成为评论。
| 归档时间: |
|
| 查看次数: |
140 次 |
| 最近记录: |