Skip to content
Myr

Merge pull request #82 from bep/mousetrap

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

Add mousetrap for Windows users

authored by Eric Paris · committed by Eric Paris · parents 0ea881c, beda194 · Browse files · 2 files+20 added−2 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+20 added−2 removed

  • other:+20 added−2 removed

2 files+20 added−2 removed

modified:cobra.go+8 added
29 unmodified lines
30// automatic prefix matching can be a dangerous thing to automatically enable in CLI tools.31// Set this to true to enable it32var EnablePrefixMatching bool = false3334// enables an information splash screen on Windows if the CLI is started from explorer.exe.35var EnableWindowsMouseTrap bool = true3637var MousetrapHelpText string = `This is a command line tool3839You need to open cmd.exe and run it from there.40`4142//OnInitialize takes a series of func() arguments and appends them to a slice of func().43func OnInitialize(y ...func()) {44 for _, x := range y {45 initializers = append(initializers, x)
67 unmodified lines
modified:command.go+12 added-2 removed
16 unmodified lines
1718import (19 "bytes"20 "fmt"21 "github.com/inconshreveable/mousetrap"22 flag "github.com/spf13/pflag"23 "io"24 "os"25 "runtime"26 "strings"2425 flag "github.com/spf13/pflag"27 "time"28)2930// Command is just that, a command for your application.31// eg. 'go run' ... 'run' is the command. Cobra requires
434 unmodified lines
466 if c.HasParent() {467 return c.Root().Execute()468 }469470 if EnableWindowsMouseTrap && runtime.GOOS == "windows" {471 if mousetrap.StartedByExplorer() {472 c.Print(MousetrapHelpText)473 time.Sleep(5 * time.Second)474 os.Exit(1)475 }476 }477478 // initialize help as the last point possible to allow for user479 // overriding480 c.initHelp()481
475 unmodified lines