From c46add8a652801b61513ad36c56759f302fbb028 Mon Sep 17 00:00:00 2001 From: Albert Nigmatzianov Date: Mon, 10 Jul 2017 21:27:14 +0200 Subject: [PATCH] Add ability to disable mousetrap Fix #486 Close #383 (no progress there) --- cobra.go | 9 +++++++++ command_win.go | 8 +------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/cobra.go b/cobra.go index 2726d19..8928cef 100644 --- a/cobra.go +++ b/cobra.go @@ -47,6 +47,15 @@ var EnablePrefixMatching = false // To disable sorting, set it to false. var EnableCommandSorting = true +// MousetrapHelpText enables an information splash screen on Windows +// if the CLI is started from explorer.exe. +// To disable the mousetrap, just set this variable to blank string (""). +// Works only on Microsoft Windows. +var MousetrapHelpText string = `This is a command line tool. + +You need to open cmd.exe and run it from there. +` + // AddTemplateFunc adds a template function that's available to Usage and Help // template generation. func AddTemplateFunc(name string, tmplFunc interface{}) { diff --git a/command_win.go b/command_win.go index 4b0eaa1..edec728 100644 --- a/command_win.go +++ b/command_win.go @@ -11,14 +11,8 @@ import ( 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() { + if MousetrapHelpText != "" && mousetrap.StartedByExplorer() { c.Print(MousetrapHelpText) time.Sleep(5 * time.Second) os.Exit(1)