mirror of
https://github.com/spf13/cobra
synced 2024-11-04 21:07:19 +00:00
67fc4837d2
new variable MousetrapDisplayDuration allows to modify the default display duration of 5s, or to completely disable the timeout and wait for the user to press the return key.
26 lines
433 B
Go
26 lines
433 B
Go
// +build windows
|
|
|
|
package cobra
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/inconshreveable/mousetrap"
|
|
)
|
|
|
|
var preExecHookFn = preExecHook
|
|
|
|
func preExecHook(c *Command) {
|
|
if MousetrapHelpText != "" && mousetrap.StartedByExplorer() {
|
|
c.Print(MousetrapHelpText)
|
|
if MousetrapDisplayDuration > 0 {
|
|
time.Sleep(MousetrapDisplayDuration)
|
|
} else {
|
|
c.Println("Press return to continue...")
|
|
fmt.Scanln()
|
|
}
|
|
os.Exit(1)
|
|
}
|
|
}
|