Last active
August 29, 2015 14:02
-
-
Save hayajo/5d5a3cfce2407964e0e9 to your computer and use it in GitHub Desktop.
golangのflagパッケージでサブコマンドのオプションをパースするサンプル
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() { | |
| sub := os.Args[1] | |
| f := flag.NewFlagSet(os.Args[0] + " " + sub, flag.ExitOnError) | |
| bar := f.String("bar", "default:value", "blur blur") | |
| f.Parse(os.Args[2:]) | |
| fmt.Println(sub, *bar) | |
| } |
Author
Author
こまかなエラー処理はやっておりません
Author
お役に立てたようで何よりです(^ν^)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
【つくった】Go言語のflagパッケージでコマンドラインオプションが取得できない気がしたので - DRYな備忘録