Created
February 6, 2017 15:12
-
-
Save s-hiiragi/a86f879e021b7a66510dd439e326bde3 to your computer and use it in GitHub Desktop.
Goでコマンドライン引数をパースするサンプル
This file contains 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
/* | |
* $ go run flag_sample.go -i 100 -s "strflag" 1 2 3 | |
* os.Args: [/.../os_args_sample -i 100 -s strflag 1 2 3] | |
* flag.Args: [1 2 3] | |
* b: false | |
* i: 100 | |
* s: strflag | |
*/ | |
package main | |
import ( | |
"fmt" | |
"os" | |
"flag" | |
) | |
func main() { | |
b := flag.Bool("b", false, "bool flag") | |
i := flag.Int("i", 0, "int flag") | |
s := flag.String("s", "default", "string flag") | |
flag.Parse() | |
fmt.Println("os.Args: ", os.Args) | |
fmt.Println("flag.Args: ", flag.Args()) | |
fmt.Println("b: ", *b) | |
fmt.Println("i: ", *i) | |
fmt.Println("s: ", *s) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment