當前位置: 首頁>>代碼示例>>Golang>>正文


Golang cmdex.RunCommandAndReturnCombinedStdoutAndStderr函數代碼示例

本文整理匯總了Golang中github.com/bitrise-io/go-utils/cmdex.RunCommandAndReturnCombinedStdoutAndStderr函數的典型用法代碼示例。如果您正苦於以下問題:Golang RunCommandAndReturnCombinedStdoutAndStderr函數的具體用法?Golang RunCommandAndReturnCombinedStdoutAndStderr怎麽用?Golang RunCommandAndReturnCombinedStdoutAndStderr使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了RunCommandAndReturnCombinedStdoutAndStderr函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: InstallWithAptGetIfNeeded

// InstallWithAptGetIfNeeded ...
func InstallWithAptGetIfNeeded(tool string, isCIMode bool) error {
	if out, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("which", tool); err != nil {
		if err.Error() == "exit status 1" && out == "" {
			// Tool isn't installed -- install it...
			if !isCIMode {
				log.Infof("This step requires %s, which is not installed", tool)
				allow, err := goinp.AskForBool("Would you like to install (" + tool + ") with brew ? [yes/no]")
				if err != nil {
					return err
				}
				if !allow {
					return errors.New("(" + tool + ") is required for step")
				}
			}

			log.Infof("(%s) isn't installed, installing...", tool)
			if out, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("sudo", "apt-get", "-y", "install", tool); err != nil {
				log.Errorf("sudo apt-get -y install %s failed -- out: (%s) err: (%s)", tool, out, err)
				return err
			}

			log.Infof(" * "+colorstring.Green("[OK]")+" %s installed", tool)
		} else {
			// which failed
			log.Errorf("which (%s) failed -- out: (%s) err: (%s)", tool, out, err)
			return err
		}
	} else if out != "" {
		// already installed
	} else {
		log.Warnf("which (%s) -- out (%s)", tool, out)
	}

	return nil
}
開發者ID:viktorbenei,項目名稱:bitrise,代碼行數:36,代碼來源:dependencies.go

示例2: InstallWithAptGetIfNeeded

// InstallWithAptGetIfNeeded ...
func InstallWithAptGetIfNeeded(aptGetDep stepmanModels.AptGetDepModel, isCIMode bool) error {
	isDepInstalled := false
	// First do a "which", to see if the binary is available.
	// Can be available from another source, not just from brew,
	// e.g. it's common to use NVM or similar to install and manage the Node.js version.
	{
		if out, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("which", aptGetDep.GetBinaryName()); err != nil {
			if err.Error() == "exit status 1" && out == "" {
				isDepInstalled = false
			} else {
				// unexpected `which` error
				return fmt.Errorf("which (%s) failed -- out: (%s) err: (%s)", aptGetDep.Name, out, err)
			}
		} else if out != "" {
			isDepInstalled = true
		} else {
			// no error but which's output was empty
			return fmt.Errorf("which (%s) failed -- no error (exit code 0) but output was empty", aptGetDep.Name)
		}
	}

	// then do a package manager specific lookup
	{
		if !isDepInstalled {
			// which did not find the binary, also check in brew,
			// whether the package is installed
			isDepInstalled = checkIfAptPackageInstalled(aptGetDep.Name)
		}
	}

	if !isDepInstalled {
		// Tool isn't installed -- install it...
		if !isCIMode {
			log.Infof(`This step requires "%s" to be available, but it is not installed.`, aptGetDep.GetBinaryName())
			allow, err := goinp.AskForBoolWithDefault(`Would you like to install the "`+aptGetDep.Name+`" package with apt-get?`, true)
			if err != nil {
				return err
			}
			if !allow {
				return errors.New("(" + aptGetDep.Name + ") is required for step")
			}
		}

		log.Infof("(%s) isn't installed, installing...", aptGetDep.Name)
		if cmdOut, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("sudo", "apt-get", "-y", "install", aptGetDep.Name); err != nil {
			log.Errorf("sudo apt-get -y install %s failed -- out: (%s) err: (%s)", aptGetDep.Name, cmdOut, err)
			return err
		}

		log.Infof(" * "+colorstring.Green("[OK]")+" %s installed", aptGetDep.Name)
	}

	return nil
}
開發者ID:bitrise-io,項目名稱:bitrise,代碼行數:55,代碼來源:dependencies.go

示例3: cmdExist

func cmdExist(cmdSlice []string) bool {
	if len(cmdSlice) == 0 {
		return false
	}

	if len(cmdSlice) == 1 {
		_, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr(cmdSlice[0])
		return (err == nil)
	}

	_, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr(cmdSlice[0], cmdSlice[1:]...)
	return (err == nil)
}
開發者ID:bitrise-io,項目名稱:steps-cocoapods-install,代碼行數:13,代碼來源:run.go

示例4: getOsAndArch

func getOsAndArch() (string, string, error) {
	osOut, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("uname", "-s")
	if err != nil {
		return "", "", err
	}

	archOut, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("uname", "-m")
	if err != nil {
		return "", "", err
	}

	return osOut, archOut, nil
}
開發者ID:birmacher,項目名稱:bitrise,代碼行數:13,代碼來源:plugins.go

示例5: InstallWithBrewIfNeeded

// InstallWithBrewIfNeeded ...
func InstallWithBrewIfNeeded(brewDep stepmanModels.BrewDepModel, isCIMode bool) error {
	isDepInstalled := false
	// First do a "which", to see if the binary is available.
	// Can be available from another source, not just from brew,
	// e.g. it's common to use NVM or similar to install and manage the Node.js version.
	if out, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("which", brewDep.GetBinaryName()); err != nil {
		if err.Error() == "exit status 1" && out == "" {
			isDepInstalled = false
		} else {
			// unexpected `which` error
			return fmt.Errorf("which (%s) failed -- out: (%s) err: (%s)", brewDep.Name, out, err)
		}
	} else if out != "" {
		isDepInstalled = true
	} else {
		// no error but which's output was empty
		return fmt.Errorf("which (%s) failed -- no error (exit code 0) but output was empty", brewDep.Name)
	}

	if !isDepInstalled {
		// which did not find the binary, also check in brew,
		// whether the package is installed
		isDepInstalled = checkIfBrewPackageInstalled(brewDep.Name)
	}

	if !isDepInstalled {
		// Tool isn't installed -- install it...
		if !isCIMode {
			log.Infof("This step requires %s, which is not installed", brewDep.Name)
			allow, err := goinp.AskForBool("Would you like to install (" + brewDep.Name + ") with brew?")
			if err != nil {
				return err
			}
			if !allow {
				return errors.New("(" + brewDep.Name + ") is required for step")
			}
		}

		log.Infof("(%s) isn't installed, installing...", brewDep.Name)
		if out, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("brew", "install", brewDep.Name); err != nil {
			log.Errorf("brew install %s failed -- out: (%s) err: (%s)", brewDep.Name, out, err)
			return err
		}
		log.Infof(" * "+colorstring.Green("[OK]")+" %s installed", brewDep.Name)
	}

	return nil
}
開發者ID:godrei,項目名稱:bitrise,代碼行數:49,代碼來源:dependencies.go

示例6: Test_InvalidCommand

func Test_InvalidCommand(t *testing.T) {
	t.Log("Invalid command")
	{
		_, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr(binPath(), "invalidcmd")
		require.EqualError(t, err, "exit status 1")
	}
}
開發者ID:bitrise-io,項目名稱:bitrise,代碼行數:7,代碼來源:invalid_command_test.go

示例7: systemOsName

func systemOsName() (string, error) {
	osOut, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("uname", "-s")
	if err != nil {
		return "", err
	}
	return strip(osOut), nil
}
開發者ID:bitrise-io,項目名稱:bitrise,代碼行數:7,代碼來源:models_methods.go

示例8: StepmanPrintRawStepList

// StepmanPrintRawStepList ...
func StepmanPrintRawStepList(collection string) error {
	logLevel := log.GetLevel().String()
	args := []string{"--debug", "--loglevel", logLevel, "step-list", "--collection", collection, "--format", "raw"}
	out, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("stepman", args...)
	if err != nil {
		return err
	}

	fmt.Println(out)
	return nil
}
開發者ID:andrewhavens,項目名稱:bitrise,代碼行數:12,代碼來源:run.go

示例9: Run

// Run ...
func (command PrintableCommand) Run() (string, error) {
	log.Debugf("=> (%#v)", command)

	out, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr(command.Name, command.Args...)
	if err != nil {
		log.Fatalf("Failed to execute:\ncommand:(%s),\noutput:(%s),\nerror:(%#v)", command.RawCommand, out, err)
	}
	log.Debugf("output:\n(%s)", out)

	return out, err
}
開發者ID:bitrise-tools,項目名稱:releaseman,代碼行數:12,代碼來源:command.go

示例10: StepmanPrintRawLocalStepInfo

// StepmanPrintRawLocalStepInfo ...
func StepmanPrintRawLocalStepInfo(pth string) error {
	logLevel := log.GetLevel().String()
	args := []string{"--debug", "--loglevel", logLevel, "step-info", "--step-yml", pth, "--format", "raw"}
	out, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("stepman", args...)
	if err != nil {
		return err
	}

	fmt.Println(out)
	return nil
}
開發者ID:andrewhavens,項目名稱:bitrise,代碼行數:12,代碼來源:run.go

示例11: Test_VersionOutput

func Test_VersionOutput(t *testing.T) {
	t.Log("Version")
	{
		out, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr(binPath(), "version")
		require.NoError(t, err)
		require.Equal(t, "1.5.0", out)
	}

	t.Log("Version --full")
	{
		out, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr(binPath(), "version", "--full")
		require.NoError(t, err)

		expectedOSVersion := fmt.Sprintf("%s (%s)", runtime.GOOS, runtime.GOARCH)
		expectedVersionOut := fmt.Sprintf(`version: 1.5.0
format version: 1.4.0
os: %s
go: %s
build number: 
commit:`, expectedOSVersion, runtime.Version())

		require.Equal(t, expectedVersionOut, out)
	}
}
開發者ID:bitrise-io,項目名稱:bitrise,代碼行數:24,代碼來源:version_test.go

示例12: RunXcodebuildCommand

// RunXcodebuildCommand ...
func (xccmd CommandModel) RunXcodebuildCommand(xcodebuildActionArgs ...string) (string, error) {
	xcodeCmdParamsToRun, err := xccmd.transformToXcodebuildParams(xcodebuildActionArgs...)
	if err != nil {
		return "", err
	}

	log.Infof("$ xcodebuild %s", cmdex.PrintableCommandArgs(true, xcodeCmdParamsToRun))
	fmt.Print("Running and analyzing log ...")
	xcoutput, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("xcodebuild", xcodeCmdParamsToRun...)
	if err != nil {
		return xcoutput, fmt.Errorf("Failed to run xcodebuild command, error: %s", err)
	}

	log.Debugf("xcoutput: %s", xcoutput)
	return xcoutput, nil
}
開發者ID:bitrise-tools,項目名稱:codesigndoc,代碼行數:17,代碼來源:xcodecmd.go

示例13: StepmanStepInfo

// StepmanStepInfo ...
func StepmanStepInfo(collection, stepID, stepVersion string) (models.StepInfoModel, error) {
	logLevel := log.GetLevel().String()
	args := []string{"--debug", "--loglevel", logLevel, "step-info", "--collection", collection,
		"--id", stepID, "--version", stepVersion}
	out, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("stepman", args...)
	if err != nil {
		return models.StepInfoModel{}, fmt.Errorf("Failed to run stepman step-info, err: %s", err)
	}

	stepInfo := models.StepInfoModel{}
	if err := json.Unmarshal([]byte(out), &stepInfo); err != nil {
		return models.StepInfoModel{}, err
	}

	return stepInfo, nil
}
開發者ID:bazscsa,項目名稱:bitrise-cli,代碼行數:17,代碼來源:run.go

示例14: EnvmanVersion

// EnvmanVersion ...
func EnvmanVersion() (version.Version, error) {
	logLevel := log.GetLevel().String()
	args := []string{"--loglevel", logLevel, "--version"}
	versionOut, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("envman", args...)
	if err != nil {
		return version.Version{}, err
	}

	versionPtr, err := version.NewVersion(versionOut)
	if err != nil {
		return version.Version{}, err
	}
	if versionPtr == nil {
		return version.Version{}, fmt.Errorf("Failed to parse version (%s)", versionOut)
	}

	return *versionPtr, nil
}
開發者ID:bitrise-io,項目名稱:bitrise,代碼行數:19,代碼來源:tool_version.go

示例15: NewRubyCommandModel

// NewRubyCommandModel ...
func NewRubyCommandModel() (RubyCommandModel, error) {
	whichRuby, err := cmdex.RunCommandAndReturnCombinedStdoutAndStderr("which", "ruby")
	if err != nil {
		return RubyCommandModel{}, err
	}

	command := RubyCommandModel{}

	if whichRuby == systemRubyPth {
		command.rubyInstallType = SystemRuby
	} else if whichRuby == brewRubyPth {
		command.rubyInstallType = BrewRuby
	} else if cmdExist([]string{"rvm", "-v"}) {
		command.rubyInstallType = RVMRuby
	} else if cmdExist([]string{"rbenv", "-v"}) {
		command.rubyInstallType = RbenvRuby
	} else {
		return RubyCommandModel{}, errors.New("unkown ruby installation type")
	}

	return command, nil
}
開發者ID:bitrise-io,項目名稱:steps-cocoapods-install,代碼行數:23,代碼來源:run.go


注:本文中的github.com/bitrise-io/go-utils/cmdex.RunCommandAndReturnCombinedStdoutAndStderr函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。