-
Notifications
You must be signed in to change notification settings - Fork 47
Add ability to self uninstall swiftly #344
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
base: main
Are you sure you want to change the base?
Add ability to self uninstall swiftly #344
Conversation
Hi @cmcgee1024 do you mind taking a look at this PR when you have time? Thanks! |
""" | ||
} | ||
|
||
let userHome = ctx.mockedHomeDir ?? fs.home |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (blocking): The current state of the user's shell may not be the same as when they initially installed swiftly. In the future, swiftly might actually install itself into all supported shells because users (like myself) switch shells quite often. So, instead of picking the current profileHome, this code should check all possible profiles for the source lines, and remove them.
import SystemPackage | ||
import Testing | ||
|
||
@Suite struct SelfUninstallTests { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: It's good to see the tests here for this functionality that are small and fast to run.
var ctx = SwiftlyTests.ctx | ||
ctx.mockedShell = shell | ||
|
||
try await SwiftlyTests.$ctx.withValue(ctx) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Add a specific withShell() to the SwiftlyTests utility functions instead of access the task local directly like this.
// Create a profile file with the source line | ||
let userHome = SwiftlyTests.ctx.mockedHomeDir! | ||
|
||
let profileHome: FilePath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Can this test invoke a swiftly init
to do the usual install behaviour instead of duplicating the logic here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, this looks good. I've added a few suggestions, and a question.
This action is irreversible. | ||
""") | ||
|
||
guard await ctx.promptForConfirmation(defaultBehavior: true) else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: Since this is a prompt for confirmation, it should also support an "--assume-yes" override in case of an automated workflow that might install and then uninstall swiftly afterwards.
swiftly self-uninstall
self-uninstall
command #84Implements the command
swiftly self-uninstall
, the ability to self uninstall swiftly incase it's no longer needed.It deletes swiftly by removing everything under
swiftBinDir
andswiftHomeDir
, and also removes the lines in shell profiles added by swiftlyTODO:
Questions:
fs.remove(atPath: ...)
?Issue
Due to the way we mock home directories, the
removesEntryFromShellProfile
fails because any shell profiles.zprofile
,.profile
will be removed alongsideswiftlyBinDir
/swiftlyHomeDir
, so the expect present check fails. Need to come up a better way to managemockedTestHome
directories