Skip to content

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

louisunlimited
Copy link
Contributor

@louisunlimited louisunlimited commented May 5, 2025

swiftly self-uninstall

Implements 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 and swiftHomeDir, and also removes the lines in shell profiles added by swiftly

TODO:

  • Implement removing shell profile entry
  • Tests for removing shell profile entry
  • Update documentation in README
  • Update docc ref

Questions:

  • Are swift bin and swift home dir guaranteed to be safe for removal with fs.remove(atPath: ...)?
  • Anything else we need to delete?
  • Specific requirements for the deletion flow?
  • What flags should we support?

Issue

Due to the way we mock home directories, the removesEntryFromShellProfile fails because any shell profiles .zprofile, .profile will be removed alongside swiftlyBinDir/swiftlyHomeDir, so the expect present check fails. Need to come up a better way to manage mockedTestHome directories

@louisunlimited louisunlimited marked this pull request as ready for review May 7, 2025 02:19
@louisunlimited
Copy link
Contributor Author

Hi @cmcgee1024 do you mind taking a look at this PR when you have time? Thanks!

"""
}

let userHome = ctx.mockedHomeDir ?? fs.home
Copy link
Member

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 {
Copy link
Member

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) {
Copy link
Member

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
Copy link
Member

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?

Copy link
Member

@cmcgee1024 cmcgee1024 left a 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 {
Copy link
Member

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.

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

Successfully merging this pull request may close these issues.

Add self-uninstall command
2 participants