title: Golang Cobra command flags in common function not getting values from cli
body: <p>I'm moving my cobra command <code>flags</code> inside a function so I can use it in other commands. I can able to see the commands but when I type the flage it always returns <code>false</code>.</p>
  
  <p>Following is my code:</p>
  
  <pre class="lang-golang prettyprint-override"><code>func NewCommand(ctx context.Context) *cobra.Command {
      var opts ListOptions
  
      cmd := &amp;cobra.Command{
          Use:   "list",
          Short: "List",
          RunE: func(cmd *cobra.Command, args []string) error {
              fmt.Println(args) // []
              opts.refs = args
              return List(ctx, gh, opts, os.Stdout)
          },
      }
  
      cmd = GetCommandFlags(cmd, opts)
      return cmd
  }
  
  // GetListCommandFlags for list
  func GetCommandFlags(cmd *cobra.Command, opts ListOptions) *cobra.Command {
      flags := cmd.Flags()
      flags.BoolVar(&amp;opts.IgnoreLatest, "ignore-latest", false, "Do not display latest")
      flags.BoolVar(&amp;opts.IgnoreOld, "ignore-old", false, "Do not display old data")
      return cmd
  }
  </code></pre>
  
  <p>So when I type the following command</p>
  
  <pre><code>data-check list --ignore-latest
  </code></pre>
  
  <p>The the flag value of <code>--ignore-latest</code> should be <code>true</code> but I get <code>false</code> as a value in <code>RunE</code> args. Am I missing something here?</p>
  
  <p><code>GetCommandFlags</code> is something I want to use it in other commands I don't want to repeat the same flags.</p>