code: func (tcmd *TopLevelCommand) HandleGlobalFlags() (*cobra.Command, []string, error) {
  	cmd := tcmd.cmd
  
  	// We manually parse the global arguments and find the
  	// subcommand in order to properly deal with plugins. We rely
  	// on the root command never having any non-flag arguments. We
  	// create our own FlagSet so that we can configure it
  	// (e.g. `SetInterspersed` below) in an idempotent way.
  	flags := pflag.NewFlagSet(cmd.Name(), pflag.ContinueOnError)
  
  	// We need !interspersed to ensure we stop at the first
  	// potential command instead of accumulating it into
  	// flags.Args() and then continuing on and finding other
  	// arguments which we try and treat as globals (when they are
  	// actually arguments to the subcommand).
  	flags.SetInterspersed(false)
  
  	// We need the single parse to see both sets of flags.
  	flags.AddFlagSet(cmd.Flags())
  	flags.AddFlagSet(cmd.PersistentFlags())
  	// Now parse the global flags, up to (but not including) the
  	// first command. The result will be that all the remaining
  	// arguments are in `flags.Args()`.
  	if err := flags.Parse(tcmd.args); err != nil {
  		// Our FlagErrorFunc uses the cli, make sure it is initialized
  		if err := tcmd.Initialize(); err != nil {
  			return nil, nil, err
  		}
  		return nil, nil, cmd.FlagErrorFunc()(cmd, err)
  	}
  
  	return cmd, flags.Args(), nil
  }
docs: // HandleGlobalFlags takes care of parsing global flags defined on the
  // command, it returns the underlying cobra command and the args it
  // will be called with (or an error).
  //
  // On success the caller is responsible for calling Initialize()
  // before calling `Execute` on the returned command.