Skip to content
Myr

added variable to allow configuration of mousetrap message duration (#809)

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

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.

authored by Willi Eggeling · committed by Eric Paris · parent 5755ecf · Browse files · 2 files+14 added−1 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+14 added−1 removed

  • other:+14 added−1 removed

2 files+14 added−1 removed

modified:cobra.go+7 added
21 unmodified lines
22 "reflect"23 "strconv"24 "strings"25 "text/template"26 "time"27 "unicode"28)2930var templateFuncs = template.FuncMap{
25 unmodified lines
5657You need to open cmd.exe and run it from there.58`5960// MousetrapDisplayDuration controls how long the MousetrapHelpText message is displayed on Windows61// if the CLI is started from explorer.exe. Set to 0 to wait for the return key to be pressed.62// To disable the mousetrap, just set MousetrapHelpText to blank string ("").63// Works only on Microsoft Windows.64var MousetrapDisplayDuration time.Duration = 5 * time.Second6566// AddTemplateFunc adds a template function that's available to Usage and Help67// template generation.68func AddTemplateFunc(name string, tmplFunc interface{}) {69 templateFuncs[name] = tmplFunc
138 unmodified lines
modified:command_win.go+7 added-1 removed
1 unmodified line
23package cobra45import (6 "fmt"7 "os"8 "time"910 "github.com/inconshreveable/mousetrap"
3 unmodified lines
1415func preExecHook(c *Command) {16 if MousetrapHelpText != "" && mousetrap.StartedByExplorer() {17 c.Print(MousetrapHelpText)17 time.Sleep(5 * time.Second)18 if MousetrapDisplayDuration > 0 {19 time.Sleep(MousetrapDisplayDuration)20 } else {21 c.Println("Press return to continue...")22 fmt.Scanln()23 }24 os.Exit(1)25 }26}