Skip to content
Myr

Add ability to disable mousetrap

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix #486 Close #383 (no progress there)

authored by Albert Nigmatzianov · committed by Albert Nigmatzianov · parent 8c6fa02 · Browse files · 2 files+10 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+10 added−7 removed

  • other:+10 added−7 removed

2 files+10 added−7 removed

modified:cobra.go+9 added
45 unmodified lines
46// EnableCommandSorting controls sorting of the slice of commands, which is turned on by default.47// To disable sorting, set it to false.48var EnableCommandSorting = true4950// MousetrapHelpText enables an information splash screen on Windows51// if the CLI is started from explorer.exe.52// To disable the mousetrap, just set this variable to blank string ("").53// Works only on Microsoft Windows.54var MousetrapHelpText string = `This is a command line tool.5556You need to open cmd.exe and run it from there.57`5859// AddTemplateFunc adds a template function that's available to Usage and Help60// template generation.61func AddTemplateFunc(name string, tmplFunc interface{}) {62 templateFuncs[name] = tmplFunc
128 unmodified lines
modified:command_win.go+1 added-7 removed
9 unmodified lines
10)1112var preExecHookFn = preExecHook1314// enables an information splash screen on Windows if the CLI is started from explorer.exe.15var MousetrapHelpText string = `This is a command line tool1617You need to open cmd.exe and run it from there.18`1914func preExecHook(c *Command) {21 if mousetrap.StartedByExplorer() {15 if MousetrapHelpText != "" && mousetrap.StartedByExplorer() {16 c.Print(MousetrapHelpText)17 time.Sleep(5 * time.Second)18 os.Exit(1)19 }
1 unmodified line