Skip to content

Instantly share code, notes, and snippets.

@hayajo
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hayajo/5d5a3cfce2407964e0e9 to your computer and use it in GitHub Desktop.
Save hayajo/5d5a3cfce2407964e0e9 to your computer and use it in GitHub Desktop.
golangのflagパッケージでサブコマンドのオプションをパースするサンプル
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)
}
@hayajo
Copy link
Author

hayajo commented Jun 3, 2014

こまかなエラー処理はやっておりません

@otiai10
Copy link

otiai10 commented Jun 3, 2014

ありがとうございます!勉強になりました!
LGTM

@hayajo
Copy link
Author

hayajo commented Jun 3, 2014

お役に立てたようで何よりです(^ν^)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment