title: Golang flag redefined
body: <p>I have flags that may be defined in multiple components.  Its not possible to know if a component has already defined a flag, as such if two components Foo and Bar require flag Zed, but Foo and Bar must define flag Zed.  In this case, Go's flag's will panic with an error flag redefined.</p>
  
  <p>Is there any way to optionally initialize a flag only if it hasn't been initialized elsewhere?  Or alternatively check if a flag has already been set and if it has then lookup the flag value?</p>
  
  <p>The only way I see to do this is with something like this:</p>
  
  <pre><code>var fooFlag *string
  
  func init() {
      if flag.Lookup("foo") == nil {
          fooFlag = flag.String("foo", "", "some flag foo")
      }
  }
  
  func initFlags() {
      if fooFlag == nil &amp;&amp; flag.Lookup("foo") != nil {
          temp := (*flag.Lookup("foo")).Value.(flag.Getter).Get().(string)
          fooFlag = &amp;temp
      }
  }
  
  func main() {
      flag.Parse()
      initFlags()
      ...
  }
  </code></pre>
  
  <p>But this is incredibly ugly (and not sure how well this will work).  Any thoughts on a better way to go about this?</p>