title: Defining Independent FlagSets in GoLang
body: <p>The Go documentation (<a href="http://golang.org/pkg/flag/">http://golang.org/pkg/flag/</a>) says:</p>
  
  <blockquote>
    <p>The FlagSet type allows one to define independent sets of flags, such as to implement subcommands in a command-line interface.</p>
  </blockquote>
  
  <p>I need this functionality but I can't figure out how to persuade the flag pkg to do it. When I define two FlagSets, parsing one of them will give me errors and warnings if the commandline has flags that are meant for the second one. Example:</p>
  
  <pre><code>f1 := flag.NewFlagSet("f1", flag.ContinueOnError)
  apply := f1.Bool("apply", false, "")
  silent := f1.Bool("silent", false, "")
  if err := f1.Parse(os.Args[1:]); err == nil {
      fmt.Println(*apply, *silent)
  }
  f2 := flag.NewFlagSet("f2", flag.ContinueOnError)
  reset := f2.Bool("reset", false, "")
  if err := f2.Parse(os.Args[1:]); err == nil {
      fmt.Println(*reset)
  }
  </code></pre>
  
  <p>I get all sorts of warnings if I try to do <code>cmd -apply</code> OR <code>cmd -reset</code>. I want to keep these FlagSets separate because I want to only have <code>-silent</code> work for <code>-apply</code>.</p>
  
  <p>What am I missing?</p>