gpt4 book ai didi

戈朗 : How to disable automatically flag sorting?

转载 作者:IT王子 更新时间:2023-10-29 01:05:52 26 4
gpt4 key购买 nike

有了flag包,我们可以像这样指定一些命令行参数:

import "flag"
fun main() {
from := flag.String("from", "", "the path to be copied")
to := flag.String("to", "", "where the data copied to")
ldb := flag.String("db", "./ldb", "the database path used during copy")
pwd := flag.String("pwd", "", "password to encrypt your data, default no encryption on your data"
flag.Parse()
...
}

当使用-h寻求帮助时,打印的消息似乎不是我提供的顺序:

-db string
the database path used during copy (default "./ldb")
-from string
the path to be copied
-pwd string
password to encrypt your data, default no encryption on your data
-to string
where the data copy to

顺序不直观,是否有其他选项可以告诉 Golang:不要自动对我的参数进行排序!

最佳答案

输出按词法排序(https://golang.org/pkg/flag/#VisitAll):

VisitAll visits the command-line flags in lexicographical order, calling fn for each. It visits all flags, even those not set.

参见:https://golang.org/src/flag/flag.go#L435

您可以使用 flag.FlagSet 并使用自定义 Usage func()

关于戈朗 : How to disable automatically flag sorting?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36326038/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com