..

Go编写命令行添加alias的方法

参考 https://github.com/golang/go/issues/35761#issuecomment-559207341 , 代码如下

package main

import "flag"

func main() {
	name := flag.String("name", "", "your name")
	flag.StringVar(name, "n", *name, "alais for --name")
	flag.Parse()
	println(*name)
}

编译

hellojukay@local test $ go build
hellojukay@local test $ ./test -h
Usage of ./test:
  -n string
        alais for --name
  -name string
        your name