Last active
April 28, 2019 01:45
-
-
Save codcodog/e121366cf6e59a39944563b8f112cd43 to your computer and use it in GitHub Desktop.
golang 命令行
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"os" | |
) | |
func main() { | |
var ( | |
hello string | |
world string | |
yes bool | |
) | |
flag.StringVar(&hello, "hello", "", "hello text") | |
flag.StringVar(&world, "world", "world", "world text") | |
flag.BoolVar(&yes, "y", false, "yes to bool") | |
textPtr := flag.String("text", "", "Text to parse. (Required)") | |
metricPtr := flag.String("metric", "chars", "Metric {chars|words|lines};. (Required)") | |
uniquePtr := flag.Bool("unique", false, "Measure unique values of a metric.") | |
flag.Parse() | |
if *textPtr == "" { | |
flag.PrintDefaults() | |
os.Exit(1) | |
} | |
fmt.Printf("textPtr: %s, metricPtr: %s, uniquePtr: %t\n", *textPtr, *metricPtr, *uniquePtr) | |
} | |
/* | |
输出如下: | |
-hello string | |
hello text | |
-metric string | |
Metric {chars|words|lines};. (Required) (default "chars") | |
-text string | |
Text to parse. (Required) | |
-unique | |
Measure unique values of a metric. | |
-world string | |
world text (default "world") | |
-y yes to bool | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment