• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang ui.Ui类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/hashicorp/otto/ui.Ui的典型用法代码示例。如果您正苦于以下问题:Golang Ui类的具体用法?Golang Ui怎么用?Golang Ui使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Ui类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: compileCallback

func (c *CompileCommand) compileCallback(ui ui.Ui) func(appfile.CompileEvent) {
	return func(raw appfile.CompileEvent) {
		switch e := raw.(type) {
		case *appfile.CompileEventDep:
			ui.Message(fmt.Sprintf(
				"Fetching dependency: %s", e.Source))
		case *appfile.CompileEventImport:
			ui.Message(fmt.Sprintf(
				"Fetching import: %s", e.Source))
		}
	}
}
开发者ID:sneal,项目名称:otto,代码行数:12,代码来源:compile.go


示例2: Run

// Run runs the given command and streams all the output to the
// given UI. It also connects stdin properly so that input works as
// expected.
func Run(uiVal ui.Ui, cmd *exec.Cmd) error {
	out_r, out_w := io.Pipe()
	cmd.Stdin = os.Stdin
	cmd.Stdout = out_w
	cmd.Stderr = out_w

	// Copy output to the UI until we can't.
	output := false
	uiDone := make(chan struct{})
	go func() {
		defer close(uiDone)
		var buf [1024]byte
		for {
			n, err := out_r.Read(buf[:])
			if n > 0 {
				output = true
				uiVal.Raw(string(buf[:n]))
			}

			// We just break on any error. io.EOF is not an error and
			// is our true exit case, but any other error we don't really
			// handle here. It probably means something went wrong
			// somewhere else anyways.
			if err != nil {
				break
			}
		}
	}()

	// Run the command
	log.Printf("[DEBUG] execDir: %s", cmd.Dir)
	log.Printf("[DEBUG] exec: %s %s", cmd.Path, strings.Join(cmd.Args[1:], " "))

	// Build a runnable command that we can log out to make things easier
	// for debugging. This lets debuging devs just copy and paste the command.
	logRunnableCommand(cmd)

	// Run
	err := Runner(cmd)

	// Wait for all the output to finish
	out_w.Close()
	<-uiDone

	if output {
		// Output one extra newline to separate output from Otto. We only
		// do this if there was any output to begin with.
		uiVal.Message("")
	}

	// Return the output from the command
	return err
}
开发者ID:mbrodala,项目名称:otto,代码行数:56,代码来源:exec.go


示例3: VerifyCreds

func VerifyCreds(ui ui.Ui, publicKeyPath string) error {
	found, err := HasKey(publicKeyPath)
	if err != nil {
		return SshAgentError(err)
	}
	if !found {
		ok, _ := GuessAndLoadPrivateKey(
			ui, publicKeyPath)
		if ok {
			ui.Message(
				"A private key was found and loaded. Otto will now check\n" +
					"the SSH Agent again and continue if the correct key is loaded")

			found, err = HasKey(publicKeyPath)
			if err != nil {
				return SshAgentError(err)
			}
		}
	}

	if !found {
		return SshAgentError(fmt.Errorf(
			"You specified an SSH public key of: %q, but the private key from this\n"+
				"keypair is not loaded the SSH Agent. To load it, run:\n\n"+
				"  ssh-add [PATH_TO_PRIVATE_KEY]",
			publicKeyPath))
	}
	return nil
}
开发者ID:sgoings,项目名称:otto,代码行数:29,代码来源:sshagent.go


示例4: Run

// Run runs the given command and streams all the output to the
// given UI. It also connects stdin properly so that input works as
// expected.
func Run(uiVal ui.Ui, cmd *exec.Cmd) error {
	out_r, out_w := io.Pipe()
	cmd.Stdin = os.Stdin
	cmd.Stdout = out_w
	cmd.Stderr = out_w

	// Copy output to the UI until we can't.
	uiDone := make(chan struct{})
	go func() {
		defer close(uiDone)
		var buf [1024]byte
		for {
			n, err := out_r.Read(buf[:])
			if n > 0 {
				uiVal.Raw(string(buf[:n]))
			}

			// We just break on any error. io.EOF is not an error and
			// is our true exit case, but any other error we don't really
			// handle here. It probably means something went wrong
			// somewhere else anyways.
			if err != nil {
				break
			}
		}
	}()

	// Run the command
	log.Printf("[DEBUG] execDir: %s", cmd.Dir)
	log.Printf("[DEBUG] exec: %s %s", cmd.Path, strings.Join(cmd.Args[1:], " "))
	err := cmd.Run()

	// Wait for all the output to finish
	out_w.Close()
	<-uiDone

	// Output one extra newline to separate output from Otto
	uiVal.Message("")

	// Return the output from the command
	return err
}
开发者ID:nvartolomei,项目名称:otto,代码行数:45,代码来源:exec.go


示例5: guessAndLoadPrivateKey

// guessAndLoadPrivateKey takes a path to a public key and determines if a
// private key exists by just stripping ".pub" from the end of it. if so,
// it attempts to load that key into the agent.
func guessAndLoadPrivateKey(ui ui.Ui, pubKeyPath string) (bool, error) {
	fullPath, err := homedir.Expand(pubKeyPath)
	if err != nil {
		return false, err
	}
	if !strings.HasSuffix(fullPath, ".pub") {
		return false, fmt.Errorf("No .pub suffix, cannot guess path.")
	}
	privKeyGuess := strings.TrimSuffix(fullPath, ".pub")
	if _, err := os.Stat(privKeyGuess); os.IsNotExist(err) {
		return false, fmt.Errorf("No file at guessed path.")
	}

	ui.Header("Loading key into SSH Agent")
	ui.Message(fmt.Sprintf(
		"The key you provided (%s) was not found in your SSH Agent.", pubKeyPath))
	ui.Message(fmt.Sprintf(
		"However, Otto found a private key here: %s", privKeyGuess))
	ui.Message(fmt.Sprintf(
		"Automatically running 'ssh-add %s'.", privKeyGuess))
	ui.Message("If your SSH key has a passphrase, you will be prompted for it.")
	ui.Message("")

	if err := sshagent.Add(ui, privKeyGuess); err != nil {
		return false, err
	}

	return true, nil
}
开发者ID:mbrodala,项目名称:otto,代码行数:32,代码来源:infra.go


示例6: guestAndLoadPrivateKey

// guestAndLoadPrivateKey 获得private key路径,只是依赖判断去除.pub部分的内容
// 如果存在则直接装在agent
func guestAndLoadPrivateKey(ui ui.Ui, pubKeyPath string) (bool, error) {
	fullPath, err := homedir.Expand(pubKeyPath)
	if err != nil {
		return false, err
	}
	if !strings.HasSuffix(fullPath, ".pub") {
		return false, fmt.Errorf("没有找到.pub后缀的文件")
	}
	privKeyGuess := strings.TrimSuffix(fullPath, ".pub")
	if _, err := os.Stat(privKeyGuess); os.IsNotExist(err) {
		return false, fmt.Errorf("文件不存在!")
	}

	ui.Header("装载key到SSH Agent")
	ui.Message(fmt.Sprintf(
		"在SSH Agent中没有你提供的key (%s)", pubKeyPath))
	ui.Message(fmt.Sprintf(
		"然而,Otto在这里:%s 找的了一个private key", privKeyGuess))
	ui.Message(fmt.Sprintf(
		"自动运行'ssh-add %s'.", privKeyGuess))
	ui.Message("如果你的SSH key有密码,你会看到如下提示")
	ui.Message("")

	if err := sshagent.Add(ui, privKeyGuess); err != nil {
		return false, err
	}

	return true, nil
}
开发者ID:kuuyee,项目名称:otto-learn,代码行数:31,代码来源:infra.go



注:本文中的github.com/hashicorp/otto/ui.Ui类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang raft.AddUniquePeer函数代码示例发布时间:2022-05-23
下一篇:
Golang otto.TestCoreConfig函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap