forked from spf13/cobra
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue spf13#195: Compile mousetrap only on Windows
* Create command_win.go and command_notwin.go for windows only code * Move call to mousetrap hook into separate preExecHook() function
1 parent
b167d9b
commit 193b182
Showing
4 changed files
with
34 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// +build !windows | ||
|
||
package cobra | ||
|
||
var preExecHookFn func(*Command) = nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// +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) | ||
} | ||
} |