Add ability to disable mousetrap
Fix #486 Close #383 (no progress there)
This commit is contained in:
		
							
								
								
									
										9
									
								
								cobra.go
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								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{}) {
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user