Exemple #1
0
func doCmd(c *cli.Context, cmd *exec.Cmd, forceRegexpSlice, suppressRegexpSlice regexpSlice) {
	var (
		out bytes.Buffer
		err error
	)

	cmd.Stderr = &out
	if !c.Bool(`omit-stdout`) {
		cmd.Stdout = &out
	}

	if err = cmd.Start(); err != nil {
		fmt.Fprintf(os.Stderr, "Could not start process: %v", err)
		os.Exit(1)
	}

	err = cmd.Wait()
	if regexpSliceMatches(out.Bytes(), forceRegexpSlice) {
		exit(out.String(), 1)
	} else if exitError, ok := err.(*exec.ExitError); ok {
		// Exited non-zero
		if status, ok := exitError.Sys().(syscall.WaitStatus); ok {
			exitCode := status.ExitStatus()
			if !intInSlice(exitCode, c.IntSlice(`suppress-exit-code`)) && !regexpSliceMatches(out.Bytes(), suppressRegexpSlice) {
				exit(out.String(), exitCode)
			}
		} else {
			exit(fmt.Sprintf("Unhandled error, sending output: %s\n%v", err, out), 1)
		}
	}
}
func getIntSliceOption(ctx *cli.Context, flag string, required bool) []int {
	slice := ctx.IntSlice(flag)
	if required && (!ctx.IsSet(flag) || len(slice) == 0) {
		exitOnError(fmt.Errorf("--%s must specify at least one integer value", flag))
	}
	return slice
}
Exemple #3
0
func create(c *cli.Context) {
	checkArgs(c)

	d := dogo.Droplet{
		Name:          c.Args().First(),
		ImageID:       c.Int("image"),
		SizeID:        dogo.SizesMap[c.String("size")],
		RegionID:      dogo.RegionsMap[c.String("region")],
		BackupsActive: c.BoolT("backups"),
	}
	keys := c.IntSlice("keys")
	network := c.BoolT("network")

	_, err := docli.CreateDroplet(d, keys, network)
	if err != nil {
		fatalf(err.Error())
	}
	fmt.Printf("Successfully queued %s for creation ... \n", d.Name)
}
Exemple #4
0
func cliRender(c *cli.Context) {
	var config flame.Config
	config.Dims.Width = 400
	config.Dims.Height = 400
	config.Iterations = 10 * 1000 * 1000
	config.Functions = []flame.FunConfig{
		{5},
		{7},
	}
	config.DataOut = c.String("dataout")
	config.DataIn = c.String("datain")
	config.NoImage = c.Bool("noimage")
	if c.String("config") != "" {
		flame.ReadConfig(c.String("config"), &config)
	}
	if c.Int("width") != 0 {
		config.Dims.Width = c.Int("width")
	}
	if c.Int("height") != 0 {
		config.Dims.Height = c.Int("height")
	}
	config.Dims.X, _ = strconv.ParseFloat(c.String("x"), 64)
	config.Dims.Y, _ = strconv.ParseFloat(c.String("y"), 64)
	config.Dims.Xscale, _ = strconv.ParseFloat(c.String("xscale"), 64)
	config.Dims.Yscale, _ = strconv.ParseFloat(c.String("yscale"), 64)
	if c.Int("iterations") != 0 {
		config.Iterations = c.Int("iterations")
	}
	if len(c.IntSlice("f")) != 0 {
		config.Functions = make([]flame.FunConfig, len(c.IntSlice("f")))
		for i, v := range c.IntSlice("f") {
			config.Functions[i] = flame.FunConfig{v}
		}
	}
	outfile := "-"
	if c.String("outfile") != "" {
		outfile = c.String("outfile")
	}
	image, _ := flame.Flame(config)
	if image != nil {
		write(outfile, image)
	}
}