mirror of
https://github.com/spf13/cobra
synced 2024-11-18 03:37:11 +00:00
193b182195
* Create command_win.go and command_notwin.go for windows only code * Move call to mousetrap hook into separate preExecHook() function
26 lines
482 B
Go
26 lines
482 B
Go
// +build windows
|
|
|
|
package cobra
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/inconshreveable/mousetrap"
|
|
)
|
|
|
|
var preExecHookFn = preExecHook
|
|
|
|
// enables an information splash screen on Windows if the CLI is started from explorer.exe.
|
|
var MousetrapHelpText string = `This is a command line tool
|
|
|
|
You need to open cmd.exe and run it from there.
|
|
`
|
|
|
|
func preExecHook(c *Command) {
|
|
if mousetrap.StartedByExplorer() {
|
|
c.Print(MousetrapHelpText)
|
|
time.Sleep(5 * time.Second)
|
|
os.Exit(1)
|
|
}
|
|
}
|