本文共 440 字,大约阅读时间需要 1 分钟。
package mainimport ( "flag" "strings" "os" "fmt")var ARGS stringfunc main() { var uptime *bool = new(bool) flag.BoolVar(uptime,"u", false, "print system uptime") flag.Parse() ARGS = strings.Join(flag.Args(), " ") if len(os.Args) < 2 { flag.Usage() os.Exit(1) } if *uptime { fmt.Println("12 days") }}