Esempio n. 1
0
func RunCommandMoreBetter(cmd command.Command, requirementsFactory *testreq.FakeReqFactory, args ...string) (result RunCommandResult) {
	defer func() {
		errMsg := recover()
		if errMsg == nil {
			return
		}

		if errMsg != nil && errMsg != testterm.QuietPanic {
			panic(errMsg)
		}

		result = RunCommandResultFailed
	}()

	context := NewContext(cmd.Metadata().Name, args)
	requirements, err := cmd.GetRequirements(requirementsFactory, context)
	if err != nil {
		return RunCommandResultRequirementsFailed
	}

	for _, requirement := range requirements {
		success := requirement.Execute()
		if !success {
			return RunCommandResultRequirementsFailed
		}
	}

	cmd.Run(context)

	return RunCommandResultSuccess
}
Esempio n. 2
0
func RunCommand(cmd command.Command, args []string, requirementsFactory *testreq.FakeReqFactory) (passedRequirements bool) {
	context := NewContext(cmd.Metadata().Name, args)

	defer func() {
		errMsg := recover()

		if errMsg != nil && errMsg != testterm.QuietPanic {
			panic(errMsg)
		}
	}()

	CommandDidPassRequirements = false

	requirements, err := cmd.GetRequirements(requirementsFactory, context)
	if err != nil {
		return
	}

	for _, requirement := range requirements {
		success := requirement.Execute()
		if !success {
			return
		}
	}

	passedRequirements = true
	CommandDidPassRequirements = true
	cmd.Run(context)

	return
}