简体   繁体   English

使用 Cobra 和 Viper 在 Go 中配置默认​​目录路径

[英]Configure a default directory path in Go with Cobra and Viper

I want the user of my CLI app to enter a specific path where they want to save files.我希望我的 CLI 应用程序的用户输入他们想要保存文件的特定路径。 I tried to use Cobra's --config flag but I don't know how to.我尝试使用 Cobra 的 --config 标志,但我不知道如何使用。

Example:例子:

app --config path "~/Documents/"

How could I do this?我怎么能这样做?

您可以尝试分离绝对路径。

app --config path "$HOME/Documents/"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM