當前位置: 首頁>>代碼示例>>Golang>>正文


Golang mousetrap.StartedByExplorer函數代碼示例

本文整理匯總了Golang中github.com/inconshreveable/mousetrap.StartedByExplorer函數的典型用法代碼示例。如果您正苦於以下問題:Golang StartedByExplorer函數的具體用法?Golang StartedByExplorer怎麽用?Golang StartedByExplorer使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了StartedByExplorer函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Execute

// Call execute to use the args (os.Args[1:] by default)
// and run through the command tree finding appropriate matches
// for commands and then corresponding flags.
func (c *Command) Execute() (err error) {

	// Regardless of what command execute is called on, run on Root only
	if c.HasParent() {
		return c.Root().Execute()
	}

	if EnableWindowsMouseTrap && runtime.GOOS == "windows" {
		if mousetrap.StartedByExplorer() {
			c.Print(MousetrapHelpText)
			time.Sleep(5 * time.Second)
			os.Exit(1)
		}
	}

	// initialize help as the last point possible to allow for user
	// overriding
	c.initHelpCmd()

	var args []string

	if len(c.args) == 0 {
		args = os.Args[1:]
	} else {
		args = c.args
	}

	cmd, flags, err := c.Find(args)
	if err != nil {
		// If found parse to a subcommand and then failed, talk about the subcommand
		if cmd != nil {
			c = cmd
		}
		if !c.SilenceErrors {
			c.Println("Error:", err.Error())
			c.Printf("Run '%v --help' for usage.\n", c.CommandPath())
		}
		return err
	}

	err = cmd.execute(flags)
	if err != nil {
		// If root command has SilentUsage flagged,
		// all subcommands should respect it
		if !cmd.SilenceUsage && !c.SilenceUsage {
			c.Println(cmd.UsageString())
		}
		// If root command has SilentErrors flagged,
		// all subcommands should respect it
		if !cmd.SilenceErrors && !c.SilenceErrors {
			if err == flag.ErrHelp {
				cmd.HelpFunc()(cmd, args)
				return nil
			}
			c.Println("Error:", err.Error())
		}
		return err
	}
	return
}
開發者ID:lebauce,項目名稱:skydive,代碼行數:63,代碼來源:command.go

示例2: Mousetrap

func Mousetrap(app *cli.App) {
	oldBefore := app.Before
	app.Before = func(c *cli.Context) error {
		if mousetrap.StartedByExplorer() {
			cmd := exec.Command(os.Args[0], os.Args[1:]...)
			cmd.Env = append(os.Environ(), "MOUSETRAP=1")
			cmd.Stdin = os.Stdin
			cmd.Stdout = os.Stdout
			cmd.Stderr = os.Stderr
			cmd.Run()
			cmd = exec.Command("cmd.exe", "/K")
			cmd.Env = os.Environ()
			cmd.Stdin = os.Stdin
			cmd.Stdout = os.Stdout
			cmd.Stderr = os.Stderr
			err := cmd.Run()
			if err != nil {
				fmt.Println("Failed to execute sub-process. Error:", err)
				os.Exit(1)
			}
			os.Exit(0)
		}
		if oldBefore == nil {
			return nil
		}
		return oldBefore(c)
	}
}
開發者ID:postfix,項目名稱:axiom,代碼行數:28,代碼來源:axiom.go

示例3: preExecHook

func preExecHook(c *Command) {
	if mousetrap.StartedByExplorer() {
		c.Print(MousetrapHelpText)
		time.Sleep(5 * time.Second)
		os.Exit(1)
	}
}
開發者ID:camlistore,項目名稱:camlistore,代碼行數:7,代碼來源:command_win.go

示例4: init

func init() {
	if mousetrap.StartedByExplorer() {
		fmt.Println("Don't double-click ponydownloader")
		fmt.Println("You need to open cmd.exe and run it from the command line!")
		time.Sleep(5 * time.Second)
		os.Exit(1)
	}
}
開發者ID:NHOrus,項目名稱:ponydownloader,代碼行數:8,代碼來源:init_windows.go

示例5: init

func init() {
	if runtime.GOOS == "windows" {
		if mousetrap.StartedByExplorer() {
			fmt.Println("Don't double-click ngrok!")
			fmt.Println("You need to open cmd.exe and run it from the command line!")
			time.Sleep(5 * time.Second)
			os.Exit(1)
		}
	}
}
開發者ID:0x19,項目名稱:ngrok,代碼行數:10,代碼來源:main.go

示例6: Execute

// Call execute to use the args (os.Args[1:] by default)
// and run through the command tree finding appropriate matches
// for commands and then corresponding flags.
func (c *Command) Execute() (err error) {

	// Regardless of what command execute is called on, run on Root only
	if c.HasParent() {
		return c.Root().Execute()
	}

	if EnableWindowsMouseTrap && runtime.GOOS == "windows" {
		if mousetrap.StartedByExplorer() {
			c.Print(MousetrapHelpText)
			time.Sleep(5 * time.Second)
			os.Exit(1)
		}
	}

	// initialize help as the last point possible to allow for user
	// overriding
	c.initHelp()

	var args []string

	if len(c.args) == 0 {
		args = os.Args[1:]
	} else {
		args = c.args
	}

	if len(args) == 0 {
		// Only the executable is called and the root is runnable, run it
		if c.Runnable() {
			err = c.execute([]string(nil))
		} else {
			c.Help()
		}
	} else {
		cmd, flags, e := c.Find(args)
		if e != nil {
			err = e
		} else {
			err = cmd.execute(flags)
		}
	}

	if err != nil {
		if err == flag.ErrHelp {
			c.Help()

		} else {
			c.Println("Error:", err.Error())
			c.Printf("Run '%v help' for usage.\n", c.Root().Name())
		}
	}

	return
}
開發者ID:SivagnanamCiena,項目名稱:calico-kubernetes,代碼行數:58,代碼來源:command.go

示例7: main


//.........這裏部分代碼省略.........
	drawing.DefaultSettings.SolidFillOnly = *noPatterns
	drawing.DefaultSettings.DomainLabelStyle = *domainLabels
	drawing.DefaultSettings.SynonymousColor = *synColor
	drawing.DefaultSettings.MutationColor = *mutColor
	drawing.DefaultSettings.GraphicWidth = float64(*width)

	if *fontPath == "" {
		err := drawing.LoadDefaultFont()
		if err != nil {
			fmt.Fprintln(os.Stderr, "ERROR: Unable to find Arial.ttf - Which is required for accurate font sizing.")
			fmt.Fprintln(os.Stderr, "       Please use -f=/path/to/arial.ttf or the TrueType (.ttf) font of your choice.")
			// continue in the hopes that SVG rendering will be ok...
			//os.Exit(1)
		}
	} else {
		fname := path.Base(*fontPath)
		fname = strings.TrimSuffix(fname, path.Ext(fname))
		err := drawing.LoadFont(fname, *fontPath)
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			os.Exit(1)
		}
	}

	var err error
	varStart := 0
	acc := ""
	geneSymbol := ""
	if *uniprot == "" && flag.NArg() > 0 {
		geneSymbol = flag.Arg(0)
		varStart = 1

		if *queryDB == "GENENAME" {
			fmt.Fprintln(os.Stderr, "HGNC Symbol: ", flag.Arg(0))
			acc, err = data.GetProtID(flag.Arg(0))
		} else {
			fmt.Fprintln(os.Stderr, "Searching for ID: ", flag.Arg(0))
			acc, err = data.GetProtMapping(*queryDB, flag.Arg(0))
		}

		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			os.Exit(1)
		}

		fmt.Fprintln(os.Stderr, "Uniprot/SwissProt Accession: ", acc)
	}

	if *uniprot != "" {
		acc = *uniprot
	}

	if flag.NArg() == 0 && *uniprot == "" {
		flag.Usage()

		if mousetrap.StartedByExplorer() {
			fmt.Fprintln(os.Stderr, `!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

This is a command-line utility for pipeline processing, you probably don't want
to double-click it! Open your command prompt with 'cmd.exe' and try again.

Press Enter/Ctrl-C to quit.`)
			fmt.Scanln(&acc)
		}
		os.Exit(1)
	}

	var d *data.PfamGraphicResponse
	if *localPath != "" {
		d, err = data.GetLocalPfamGraphicData(*localPath)
	} else {
		d, err = data.GetPfamGraphicData(acc)
	}
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	if geneSymbol == "" {
		geneSymbol = d.Metadata.Identifier
		fmt.Fprintln(os.Stderr, "Pfam Symbol: ", geneSymbol)
	}

	if *output == "" {
		*output = geneSymbol + ".svg"
	}

	f, err := os.OpenFile(*output, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0644)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	defer f.Close()

	fmt.Fprintln(os.Stderr, "Drawing diagram to", *output)
	if strings.HasSuffix(strings.ToLower(*output), ".png") {
		drawing.DrawPNG(f, *dpi, flag.Args()[varStart:], d)
	} else {
		drawing.DrawSVG(f, flag.Args()[varStart:], d)
	}
}
開發者ID:pbnjay,項目名稱:lollipops,代碼行數:101,代碼來源:main.go


注:本文中的github.com/inconshreveable/mousetrap.StartedByExplorer函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。