Example #1
0
func (c *SwitchAtLeastCommand) Run(args []string) int {
	if len(args) == 0 {
		fmt.Printf(FailInGetVersion)
		return 1
	}

	xcodeList, xcodeError := function.GetXcodeList(function.ApplicationsPath)
	if xcodeError != nil {
		fmt.Printf(FailInMakingAListOfXcodes)
		return 1
	}

	if model.IsShortVersion(args[0]) {
		v, _ := model.NewShortVersion(args[0])

		for i := len(xcodeList) - 1; i >= 0; i-- {
			if model.EqualsForShortVersion(v, xcodeList[i].Version.Short) || model.LessForShortVersion(v, xcodeList[i].Version.Short) {
				_, execError := function.ExecXcodeSelectSwitchOutput(xcodeList[i].AppPath + function.PathToDeveloperDirectoryPath)
				if execError == nil {
					fmt.Printf(SucceedInSwitching, model.GetShortVersionInString(xcodeList[i].Version.Short), model.GetProductBuildVersionInString(xcodeList[i].Version.ProductBuild))
					return 0
				} else {
					fmt.Printf(FailInSwitching, model.GetShortVersionInString(xcodeList[i].Version.Short))
					return 1
				}
			}
		}
		fmt.Printf(FailInFindingXcodeAtLeast, model.GetShortVersionInString(v))

	} else if model.IsProductBuildVersion(args[0]) {
		v, _ := model.NewProductBuildVersion(args[0])

		for i := len(xcodeList) - 1; i >= 0; i-- {
			if model.EqualsForProductBuildVersion(v, xcodeList[i].Version.ProductBuild) || model.LessForProductBuildVersion(v, xcodeList[i].Version.ProductBuild) {
				_, execError := function.ExecXcodeSelectSwitchOutput(xcodeList[i].AppPath + function.PathToDeveloperDirectoryPath)
				if execError == nil {
					fmt.Printf(SucceedInSwitching, model.GetShortVersionInString(xcodeList[i].Version.Short), model.GetProductBuildVersionInString(xcodeList[i].Version.ProductBuild))
					return 0
				} else {
					fmt.Printf(FailInSwitching, model.GetProductBuildVersionInString(xcodeList[i].Version.ProductBuild))
					return 1
				}
			}
		}
		fmt.Printf(FailInFindingXcodeAtLeast, model.GetProductBuildVersionInString(v))

	} else {
		fmt.Printf(FailInGetVersion)
	}
	return 1
}
Example #2
0
func (c *SwitchLatestCommand) Run(args []string) int {
	xcodeList, xcodeError := function.GetXcodeList(function.ApplicationsPath)
	if xcodeError != nil {
		fmt.Printf(FailInMakingAListOfXcodes)
		return 1
	}

	if len(xcodeList) == 0 {
		fmt.Printf(FailInFindingXcodeLatest)
		return 1
	}

	xcode := xcodeList[len(xcodeList)-1]
	_, execError := function.ExecXcodeSelectSwitchOutput(xcode.AppPath + function.PathToDeveloperDirectoryPath)
	if execError == nil {
		fmt.Printf(SucceedInSwitching, model.GetShortVersionInString(xcode.Version.Short), model.GetProductBuildVersionInString(xcode.Version.ProductBuild))
		return 0
	} else {
		fmt.Printf(FailInSwitching, model.GetShortVersionInString(xcode.Version.Short)+" "+model.GetProductBuildVersionInString(xcode.Version.ProductBuild))
		return 1
	}

}
Example #3
0
func (c *ListCommand) Run(args []string) int {
	xcodeList, xcodeError := function.GetXcodeList(function.ApplicationsPath)
	if xcodeError != nil {
		fmt.Printf(FailInMakingAListOfXcodes)
		os.Exit(1)
	}

	activeDeveloperDirectoryPath, _ := function.GetActiveDeveloperDirectoryPath()
	for _, xcode := range xcodeList {
		if activeDeveloperDirectoryPath == xcode.AppPath+function.PathToDeveloperDirectoryPath {
			fmt.Printf("* ")
		} else {
			fmt.Printf("  ")
		}

		fmt.Printf("%s (%s %s)\n", xcode.AppName, model.GetShortVersionInString(xcode.Version.Short), model.GetProductBuildVersionInString(xcode.Version.ProductBuild))
	}
	return 0
}
Example #4
0
func (c *SwitchCompatibleCommand) Run(args []string) int {
	if len(args) == 0 {
		fmt.Printf(FailInGetVersion)
		return 1
	}

	xcodeList, xcodeError := function.GetXcodeList(function.ApplicationsPath)
	if xcodeError != nil {
		fmt.Printf(FailInMakingAListOfXcodes)
		return 1
	}

	if model.IsShortVersion(args[0]) {
		v, _ := model.NewShortVersion(args[0])

		excess, excessError := model.GetExcessCompatibleShortVersion(args[0])
		if excessError != nil {
			fmt.Printf(FailInGetVersion)
			return 1
		}

		for i := len(xcodeList) - 1; i >= 0; i-- {
			if !model.EqualsForShortVersion(xcodeList[i].Version.Short, v) && model.LessForShortVersion(xcodeList[i].Version.Short, v) {
				break
			}
			if !model.EqualsForShortVersion(xcodeList[i].Version.Short, excess) && model.LessForShortVersion(xcodeList[i].Version.Short, excess) {
				_, execError := function.ExecXcodeSelectSwitchOutput(xcodeList[i].AppPath + function.PathToDeveloperDirectoryPath)
				if execError == nil {
					fmt.Printf(SucceedInSwitching, model.GetShortVersionInString(xcodeList[i].Version.Short), model.GetProductBuildVersionInString(xcodeList[i].Version.ProductBuild))
					return 0
				} else {
					fmt.Printf(FailInSwitching, model.GetShortVersionInString(xcodeList[i].Version.Short))
					return 1
				}
			}
		}
		fmt.Printf(FailInFindingXcodeCompatible, model.GetShortVersionInString(v))

	} else if model.IsProductBuildVersion(args[0]) {
		v, _ := model.NewProductBuildVersion(args[0])

		excess, excessError := model.GetExcessCompatibleProductBuildVersion(args[0])
		if excessError != nil {
			fmt.Printf(FailInGetVersion)
			return 1
		}

		xcodeLists, xcodeError := function.GetXcodeList(function.ApplicationsPath)
		if xcodeError != nil {
			fmt.Printf(FailInMakingAListOfXcodes)
			return 1
		}

		for i := len(xcodeLists) - 1; i >= 0; i-- {
			if !model.EqualsForProductBuildVersion(xcodeLists[i].Version.ProductBuild, v) && model.LessForProductBuildVersion(xcodeLists[i].Version.ProductBuild, v) {
				break
			}
			if !model.EqualsForProductBuildVersion(xcodeLists[i].Version.ProductBuild, excess) && model.LessForProductBuildVersion(xcodeLists[i].Version.ProductBuild, excess) {
				_, execError := function.ExecXcodeSelectSwitchOutput(xcodeLists[i].AppPath + function.PathToDeveloperDirectoryPath)
				if execError == nil {
					fmt.Printf(SucceedInSwitching, model.GetShortVersionInString(xcodeLists[i].Version.Short), model.GetProductBuildVersionInString(xcodeLists[i].Version.ProductBuild))
					return 0
				} else {
					fmt.Println(execError)
					return 1
				}
			}
		}
		fmt.Printf(FailInFindingXcodeCompatible, model.GetProductBuildVersionInString(v))

	} else {
		fmt.Printf(FailInGetVersion)
	}
	return 1
}