Example #1
0
func cmdBuildsImport(c *cli.Context) error {
	_, app, err := stdcli.DirApp(c, ".")
	if err != nil {
		return stdcli.Error(err)
	}

	if stdcli.IsTerminal(os.Stdin) && c.String("file") == "" {
		return stdcli.Error(fmt.Errorf("please pipe a file into this command or specify -f"))
	}

	in := os.Stdin
	if file := c.String("file"); file != "" {
		fd, err := os.Open(file)
		if err != nil {
			return stdcli.Error(err)
		}
		defer fd.Close()
		in = fd
	}

	out := os.Stdout

	if c.Bool("id") {
		out = os.Stderr
	}

	build, err := rackClient(c).ImportBuild(app, in, client.ImportBuildOptions{Progress: progress("Uploading: ", "Importing build... ", out)})
	if err != nil {
		return stdcli.Error(err)
	}

	fmt.Fprintf(out, "\nRelease: %s\n", build.Release)

	if c.Bool("id") {
		fmt.Println(build.Release)
	}

	return nil
}
Example #2
0
func cmdBuildsExport(c *cli.Context) error {
	_, app, err := stdcli.DirApp(c, ".")
	if err != nil {
		return stdcli.Error(err)
	}

	if stdcli.IsTerminal(os.Stdout) && c.String("file") == "" {
		return stdcli.Error(fmt.Errorf("please pipe the output of this command to a file or specify -f"))
	}

	if len(c.Args()) != 1 {
		stdcli.Usage(c, "export")
		return nil
	}

	build := c.Args()[0]

	fmt.Fprintf(os.Stderr, "Exporting %s... ", build)

	out := os.Stdout

	if file := c.String("file"); file != "" {
		fd, err := os.OpenFile(file, os.O_CREATE|os.O_WRONLY, 0644)
		if err != nil {
			return stdcli.Error(err)
		}
		defer fd.Close()
		out = fd
	}

	if err := rackClient(c).ExportBuild(app, build, out); err != nil {
		return stdcli.Error(err)
	}

	fmt.Fprintf(os.Stderr, "OK\n")

	return nil
}
Example #3
0
File: env.go Project: convox/rack
func cmdEnvSet(c *cli.Context) error {
	_, app, err := stdcli.DirApp(c, ".")
	if err != nil {
		return stdcli.Error(err)
	}

	env, err := rackClient(c).GetEnvironment(app)
	if err != nil {
		return stdcli.Error(err)
	}

	data := ""

	for key, value := range env {
		data += fmt.Sprintf("%s=%s\n", key, value)
	}

	if !stdcli.IsTerminal(os.Stdin) {
		in, err := ioutil.ReadAll(os.Stdin)
		if err != nil {
			return stdcli.Error(err)
		}

		scanner := bufio.NewScanner(bytes.NewReader(in))
		for scanner.Scan() {
			parts := strings.SplitN(scanner.Text(), "=", 2)

			if len(parts) == 2 {
				if key := strings.TrimSpace(parts[0]); key != "" {
					val := parts[1]

					// heroku env -s adds leading and trailing single quotes to val. Strip.
					if string(val[0]) == "'" && string(val[len(val)-1]) == "'" {
						val = val[1 : len(val)-2]
					}
					data += fmt.Sprintf("%s=%s\n", key, val)
				}
			}
		}
	}

	for _, value := range c.Args() {
		data += fmt.Sprintf("%s\n", value)
	}

	fmt.Print("Updating environment... ")

	_, releaseID, err := rackClient(c).SetEnvironment(app, strings.NewReader(data))
	if err != nil {
		return stdcli.Error(err)
	}

	fmt.Println("OK")

	if releaseID != "" {
		if c.Bool("promote") {
			fmt.Printf("Promoting %s... ", releaseID)

			_, err = rackClient(c).PromoteRelease(app, releaseID)
			if err != nil {
				return stdcli.Error(err)
			}

			fmt.Println("OK")
		} else {
			fmt.Printf("To deploy these changes run `convox releases promote %s`\n", releaseID)
		}
	}

	return nil
}