Ejemplo n.º 1
0
Archivo: main.go Proyecto: NetSys/quilt
// Main is the main function for inspect tool. Helps visualize stitches.
func Main(opts []string) int {
	if arglen := len(opts); arglen < 2 {
		fmt.Println("not enough arguments: ", arglen)
		Usage()
		return 1
	}

	configPath := opts[0]

	spec, err := stitch.FromFile(configPath, stitch.DefaultImportGetter)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return 1
	}

	graph, err := stitch.InitializeGraph(spec)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		return 1
	}

	switch opts[1] {
	case "pdf", "ascii", "graphviz":
		viz(configPath, spec, graph, opts[1])
	default:
		Usage()
		return 1
	}

	return 0
}
Ejemplo n.º 2
0
func configRunOnce(configPath string, quiltPath string) error {
	stitch.HTTPGet = func(url string) (*http.Response, error) {
		resp := http.Response{
			Body: ioutil.NopCloser(bytes.NewBufferString("")),
		}
		return &resp, nil
	}
	_, err := stitch.FromFile(configPath, stitch.ImportGetter{
		Path: quiltPath,
	})
	return err
}
Ejemplo n.º 3
0
Archivo: run.go Proyecto: NetSys/quilt
// Run starts the run for the provided Stitch.
func (rCmd *Run) Run() int {
	stitchPath := rCmd.stitch
	compiled, err := stitch.FromFile(stitchPath, stitch.DefaultImportGetter)
	if err != nil && os.IsNotExist(err) && !filepath.IsAbs(stitchPath) {
		// Automatically add the ".js" file suffix if it's not provided.
		if !strings.HasSuffix(stitchPath, ".js") {
			stitchPath += ".js"
		}
		compiled, err = stitch.FromFile(
			filepath.Join(stitch.GetQuiltPath(), stitchPath),
			stitch.DefaultImportGetter)
	}
	if err != nil {
		// Print the stacktrace if it's an Otto error.
		if ottoError, ok := err.(*otto.Error); ok {
			log.Error(ottoError.String())
		} else {
			log.Error(err)
		}
		return 1
	}
	deployment := compiled.String()

	c, err := rCmd.clientGetter.Client(rCmd.common.host)
	if err != nil {
		log.Error(err)
		return 1
	}
	defer c.Close()

	curr, err := getCurrentDeployment(c)
	if err != nil {
		log.WithError(err).Error("Unable to get current deployment.")
		return 1
	}

	if !rCmd.force && curr != emptyDeployment {
		diff, err := diffDeployment(curr, deployment)
		if err != nil {
			log.WithError(err).Error("Unable to diff deployments.")
			return 1
		}

		if diff == "" {
			fmt.Println("No change.")
		} else {
			fmt.Println(diff)
		}
		shouldDeploy, err := confirm(os.Stdin, "Continue with deployment?")
		if err != nil {
			log.WithError(err).Error("Unable to get user response.")
			return 1
		}

		if !shouldDeploy {
			fmt.Println("Deployment aborted by user.")
			return 0
		}
	}

	err = c.Deploy(deployment)
	if err != nil {
		log.WithError(err).Error("Error while starting run.")
		return 1
	}

	log.Debug("Successfully started run")
	return 0
}