golang flag 加强版

xiaoxiao2021-02-27  363

flag plus 让flag单个标记支持多个参数

https://code.csdn.net/leezjl/flagp/tree/master

添加 flagp.StringSlice(name string, value []string, usage string)添加 flagp.StringSliceVar(p *[]string, name string, value []string, usage string)

Example

b := flagp.Bool("b", false, "bool") dirs := flagp.StringSlice("d", []string{}, "需要操作的文件/目录, tab切起来") n := flagp.Int("n", 0, "number") xFiles := flagp.StringSlice("x", []string{}, "需要忽略的文件/目录, tab切起来") flagp.Parse() flagp.Usage() fmt.Println("dirs = ", *dirs, "xFiles = ", *xFiles, "n = ", *n, "b = ", *b) $ go run upfl.go -b -d hehe/ xx/ -n 123 -x xx/ dd/ Usage of upfl: -b bool -d []string 需要操作的文件/目录, tab切起来 -n int number -x []string 需要忽略的文件/目录, tab切起来 dirs = [hehe/ xx/] , xFiles = [xx/ dd/] , n = 123 , b = true
转载请注明原文地址: https://www.6miu.com/read-3337.html

最新回复(0)