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 option to install #182

Merged
merged 9 commits into from
Oct 26, 2022

Conversation

tahirmt
Copy link
Contributor

@tahirmt tahirmt commented Feb 4, 2022

Adds options --select and --update to install command.

Details

Copy link

@Kingkhalifa195 Kingkhalifa195 left a comment

Choose a reason for hiding this comment

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

Will try to check this out

@@ -164,6 +164,11 @@ public final class XcodeInstaller {
Current.shell.exit(0)
}
}

/// Perform the install but don't exit out but return the installed xcode version as output instead
public func installWithoutLogging(_ installationType: InstallationType, dataSource: DataSource, downloader: Downloader, destination: Path) -> Promise<InstalledXcode> {

Choose a reason for hiding this comment

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

I keep having set back anytime I installed it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you please elaborate?

@tahirmt tahirmt force-pushed the add-select-option-to-install branch 2 times, most recently from 0d0ac3c to 8061e41 Compare March 17, 2022 18:27
@rogerluan
Copy link
Contributor

@tahirmt thank you for this PR! This makes total sense to me 💯

@MattKiazyk this would also be aligned with xcpretty/xcode-install#467, since xcode-install's default behavior automatically selects the Xcode version that was just installed, and it would be a huge improvement over xcode-install and xcodes if we could also optionally run update automatically right before installing (otherwise Xcode versions that exist might not be found). I had to work-around this behavior implementing a "pre-install update" behavior here but it'd be great if it was built-in into xcodes ☺️

I'll review this PR to help move it forward 💪

return selectXcode(shouldPrint: print, pathOrVersion: version, directory: destination, fallbackToInteractive: false)
} else {
return Promise { _ in
throw InstallError.notAlreadyInstalled
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a huge fan of throwing just to get to a catch. Can you refactor this a bit so that it's a bit simpler around the different options. That may involved some new functions to make things a bit cleaner.

Let me know if you need some help around this. Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did some refactor. Let me know what you think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think unit testing is where I'm kind of lost and will require some help

Copy link
Contributor

@MattKiazyk MattKiazyk left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

There's some coding issues around how the select parameter gets passed through. Made some comments


if select, case .version(let version) = installation {
firstly {
selectXcode(shouldPrint: print, pathOrVersion: version, directory: destination, fallbackToInteractive: false)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is incorrect - we should install first, then select after.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was done to only select if it is already installed. If the version isn't installed this will throw and then we can install it.

Copy link
Contributor

Choose a reason for hiding this comment

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

The new select flag on the install is "Select the installed xcode version after installation." which its not doing.

You're checking if the select flag is passed in, trying to select the new xcode (that isn't installed) and then installing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking of a use case where on CI you want to ensure that a certain Xcode version is installed. So you could do xcodes install x.x.x --select --update. If it's already installed you would expect it to be selected.

So with all of these options if we try to select first, we exit super early by just selecting the version. But if we don't, it will first update the list, then see that it is already installed and select it. The list update will always happen even if Xcode was already installed and it wasn't needed. If that's the behavior you prefer I can remove it.

Current.logging.log("\nXcode \(xcode.version.descriptionWithoutBuildMetadata) has been installed to \(xcode.path.string)".green)

// Install was successful, now select it
return selectXcode(shouldPrint: print, pathOrVersion: xcode.path.string, directory: destination, fallbackToInteractive: false)
Copy link
Contributor

Choose a reason for hiding this comment

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

The selectXcode here isn't looking at the select option passed in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, this line will not get executed if select is false because install would exit early from the step before. That's why I don't have a check here.

Copy link
Contributor Author

@tahirmt tahirmt Sep 29, 2022

Choose a reason for hiding this comment

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

Unless I missed something in how Current.shell.exit(0) works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep I tested it out

➜  xcodes git:(add-select-option-to-install) swift run xcodes install 14.0.1 --experimental-unxip
Building for debugging...
Build complete! (0.08s)

Downloading with aria2
(1/6) Downloading Xcode 14.0.1+14A400: 99%
(2/6) Unarchiving Xcode (This can take a while)
Using experimental unxip. If you encounter any issues, remove the flag and try again
(3/6) Moving Xcode to /Applications/Xcode-14.0.1.app
(4/6) Moving Xcode archive Xcode-14.0.1+14A400.xip to the Trash
(5/6) Checking security assessment and code signing
(6/6) Finishing installation
xcodes requires superuser privileges in order to finish installation.
macOS User Password: 

Xcode 14.0.1 has been installed to /Applications/Xcode-14.0.1.app

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, i see now.. can we refactor that a bit.

Can we remove the exitAfterInstall property on the installer.install. It's a bit confusing on doing it there if in the end we are using that to skip the select

Instead can we pass the select option inside this function and the last step check that, selecting if user wants.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I refactored this.

@rogerluan
Copy link
Contributor

@tahirmt since #181 got merged, would you mind rebasing this branch or merging the main branch into this one? 🙇

@tahirmt tahirmt force-pushed the add-select-option-to-install branch from 60e66c8 to 873ae9d Compare September 29, 2022 11:25
@tahirmt tahirmt marked this pull request as ready for review September 29, 2022 11:26
@tahirmt tahirmt requested a review from a team as a code owner September 29, 2022 11:26
}
}
.then { xcode -> Promise<Void> in
select ? selectXcode(shouldPrint: print, pathOrVersion: xcode.path.string, directory: destination, fallbackToInteractive: false) : .init()
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry one more #picky - can we if else on this select instead of ? :

Copy link
Contributor Author

@tahirmt tahirmt left a comment

Choose a reason for hiding this comment

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

If else

Sources/xcodes/main.swift Outdated Show resolved Hide resolved
@tahirmt tahirmt force-pushed the add-select-option-to-install branch from 94b01c2 to 77d2e29 Compare October 8, 2022 02:25
@tahirmt tahirmt requested a review from MattKiazyk October 8, 2022 02:28
Copy link
Contributor

@MattKiazyk MattKiazyk left a comment

Choose a reason for hiding this comment

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

Thanks for the changes and willingness to wait.

@MattKiazyk MattKiazyk added the enhancement New feature or request label Oct 26, 2022
@MattKiazyk MattKiazyk merged commit f9771ca into XcodesOrg:main Oct 26, 2022
@tahirmt tahirmt deleted the add-select-option-to-install branch October 26, 2022 03:25
Copy link

@jokerputihboy jokerputihboy left a comment

Choose a reason for hiding this comment

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

Tepelekek

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] xcodes install *** --select
5 participants