Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add select command #89

Merged
merged 8 commits into from
May 8, 2020
Merged

Conversation

interstateone
Copy link
Contributor

@interstateone interstateone commented Apr 8, 2020

This PR adds a new select command, which uses xcode-select under the hood. The motivation for adding this feature is that for users who are installing multiple Xcode versions simultaneously, and so xcodes is valuable, switching between those versions is a likely need and not easy to do with xcode-select alone. I've been using a small shell script for many years to solve exactly this problem, but it would be nice to have this inside xcodes instead.

It can be used like this:

# Interactively select an installed Xcode

$ xcodes select
Available Xcode versions:
1) 10.1
2) 10.2.1
3) 11.0
4) 11.2
5) 11.2.1
6) 11.3
7) 11.4 (Selected)
Enter the number of the Xcode to select: 6
xcodes requires superuser privileges to select an Xcode
macOS User Password: 
Selected /Applications/Xcode-11.3.0.app/Contents/Developer

# Select an Xcode by providing a version

$ xcodes select 11.4.0
Selected /Applications/Xcode-11.4.0.app/Contents/Developer

# Select an Xcode by providing a path

$ xcodes select /Applications/Xcode-11.4.0.app
Selected /Applications/Xcode-11.4.0.app/Contents/Developer

# Print the currently selected Xcode path

$ xcodes select -p
/Applications/Xcode-11.4.0.app/Contents/Developer

The output of the xcodes list and xcodes installed commands also annotate the version that's selected in the same way.

If you uninstall the currently selected Xcode version, xcodes will automatically select the latest installed version, if there is one, so that the selected path is a valid one.

Closes #47
Closes #82

Need to make sure Current is set to .mock before XcodeList is initialized so that the cached available Xcodes file content is mocked. The let installed property was being initialized statically before setUp was invoked.
@interstateone interstateone force-pushed the add-xcode-select branch 3 times, most recently from 3d950db to 74905f0 Compare April 11, 2020 18:45
@interstateone interstateone marked this pull request as ready for review May 7, 2020 02:00
Copy link

@civatrix civatrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Love all the tests!

@interstateone interstateone merged commit 9969092 into XcodesOrg:master May 8, 2020
@interstateone interstateone deleted the add-xcode-select branch May 8, 2020 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants