github.com/searKing/golang/go@v1.2.117/flag/export_test.go (about)

     1  // Copyright 2020 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package flag_test
     6  
     7  import (
     8  	"flag"
     9  	"os"
    10  )
    11  
    12  // Additional routines compiled into the package only during testing.
    13  
    14  // ResetForTesting clears all flag state and sets the usage function as directed.
    15  // After calling ResetForTesting, parse errors in flag handling will not
    16  // exit the program.
    17  func ResetForTesting(usage func()) {
    18  	flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
    19  	flag.CommandLine.Usage = flag.Usage
    20  	flag.Usage = usage
    21  }