Esempio n. 1
0
func fmtHelp(info *api.Info) (string, error) {
	h := struct {
		*api.Info
		Commands []*tenetCommand
	}{
		Info:     info,
		Commands: tenetCommands(),
	}
	return util.FormatOutput(h, helpTemplate)
}
Esempio n. 2
0
func (c *tenetCMDs) printInfo() error {
	info, err := c.info()
	if err != nil {
		return errors.Trace(err)
	}
	text, err := util.FormatOutput(info, infoTemplate)
	if err != nil {
		return errors.Trace(err)
	}
	fmt.Println(text)
	return nil
}
Esempio n. 3
0
func (c *tenetCMDs) printCmdHelp(cmdName string) error {
	for _, cmd := range tenetCommands() {
		if cmd.Name == cmdName {
			out, err := util.FormatOutput(cmd, cmdHelpTemplate)
			if err != nil {
				return errors.Trace(err)
			}
			fmt.Print(out)
			return nil
		}
	}

	fmt.Printf("no help found for %q", cmdName)
	return nil
}
Esempio n. 4
0
func copr(c *cli.Context) {
	cliArgs := c.Args()
	if err := common.ExactArgs(c, 1); err != nil {
		common.OSErrf(err.Error())
		return
	}

	repoPath, err := exec.Command("git", "rev-parse", "--show-toplevel").Output()
	if err != nil {
		common.OSErrf(err.Error())
		return
	}
	repo := path.Base(strings.Trim(string(repoPath), "\n"))
	var fetchAll string
	if !c.Bool("skip-fetch-all") {
		fetchAll = "git fetch --all"
	}

	argParts := strings.Split(cliArgs[0], ":")
	args := map[string]string{
		"User":     argParts[0],
		"Repo":     repo,
		"Branch":   argParts[1],
		"Base":     strings.Replace(c.String("base"), ":", "/", -1),
		"FetchAll": fetchAll,
		"Host":     c.String("host"),
	}
	bashScript, err := util.FormatOutput(args, coprcmd)
	if err != nil {
		common.OSErrf(err.Error())
		return
	}

	if c.Bool("dry-run") {
		fmt.Println("execute the following bash script:")
		fmt.Println(bashScript)
		return
	}

	cmd := exec.Command("bash", "-c", bashScript)
	cmd.Stderr = os.Stderr
	cmd.Stdout = os.Stdout
	err = cmd.Run()
	if err != nil {
		common.OSErrf(err.Error())
		return
	}
}
Esempio n. 5
0
func (cfg *dockerBuildCfg) writeDockerFile(dockerfilePath string) error {
	// TODO(waigani) remove when dev is published
	tenetRelPath, _, _, err := cfg.hackedPaths()
	if err != nil {
		return errors.Trace(err)
	}

	data := dockerfileData{
		baseBuildCfg: cfg.baseBuildCfg,
		TenetRoot:    tenetRelPath, // TODO(waigani) use cfg.dir when dev is published
	}
	out, err := util.FormatOutput(data, dockerfileTmpl)
	if err != nil {
		return errors.Trace(err)
	}

	dockerfilePath = filepath.Join(cfg.dir, "Dockerfile")
	return ioutil.WriteFile(dockerfilePath, []byte(out), 0644)
}