Ejemplo n.º 1
0
func (o *Options) Command(command string) (affected []string, err error) {
	args := []string{command}
	if o.Output != "" {
		args = append(args, "-o", o.Output)
	}
	if o.ForceAll {
		args = append(args, "-a")
	}
	if o.Parallel != 0 {
		args = append(args, "-p", fmt.Sprintf("%d", o.Parallel))
	}
	if o.Compiler != "" {
		args = append(args, "-compiler", o.Compiler)
	}
	if o.GccGoFlags != "" {
		args = append(args, "-gccgoflags", o.GccGoFlags)
	}
	if o.GcFlags != "" {
		args = append(args, "-gcflags", o.GcFlags)
	}
	if o.LdFlags != "" {
		args = append(args, "-ldflags", o.LdFlags)
	}
	if o.Tags != "" {
		args = append(args, "-tags", o.Tags)
	}
	if o.Verbose {
		args = append(args, "-v")
	}
	for _, importPath := range o.ImportPaths {
		args = append(args, importPath)
	}
	bin, err := goBin(o.GoBin)
	if err != nil {
		return nil, err
	}
	streams, err := runcmd.Run(exec.Command(bin, args...))
	if err != nil {
		return nil, err
	}
	affectedBytes := bytes.Split(streams.Stderr().Bytes(), []byte("\n"))
	affected = make([]string, 0, len(affectedBytes))
	for _, importPath := range affectedBytes {
		if len(importPath) == 0 {
			continue
		}
		affected = append(affected, string(importPath))
	}
	return affected, nil
}
Ejemplo n.º 2
0
// Boot2Docker returns a DockerClient if possible configured according to
// boot2docker.
func Boot2DockerClient() (*dockerclient.DockerClient, error) {
	cmd := exec.Command("boot2docker", "shellinit")
	cmd.Env = boot2dockerEnv()
	streams, err := runcmd.Run(cmd)
	if err != nil {
		return nil, stackerr.Wrap(err)
	}

	var host, tls, certPath string
	const (
		prefixHost     = "export DOCKER_HOST="
		prefixTLS      = "export DOCKER_TLS_VERIFY="
		prefixCertPath = "export DOCKER_CERT_PATH="
	)
	for _, lineB := range bytes.Split(streams.Stdout().Bytes(), []byte("\n")) {
		line := string(bytes.TrimSpace(lineB))
		if strings.HasPrefix(line, prefixHost) {
			host = line[len(prefixHost):]
			continue
		}
		if strings.HasPrefix(line, prefixTLS) {
			tls = line[len(prefixTLS):]
			continue
		}
		if strings.HasPrefix(line, prefixCertPath) {
			certPath = line[len(prefixCertPath):]
			continue
		}
	}

	if tls == "1" {
		return DockerWithTLS(host, certPath)
	}

	client, err := dockerclient.NewDockerClient(host, nil)
	if err != nil {
		return nil, stackerr.Wrap(err)
	}
	return client, nil
}