feat(destroy): implement destroy command parity
This commit is contained in:
@@ -165,6 +165,33 @@ func (a *App) Commit(castle string, message string) error {
|
||||
return runGitWithIO(castledir, a.Stdout, a.Stderr, "commit", "-m", trimmedMessage)
|
||||
}
|
||||
|
||||
func (a *App) Destroy(castle string) error {
|
||||
if strings.TrimSpace(castle) == "" {
|
||||
castle = "dotfiles"
|
||||
}
|
||||
|
||||
castleRoot := filepath.Join(a.ReposDir, castle)
|
||||
castleInfo, err := os.Lstat(castleRoot)
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return fmt.Errorf("castle %q not found", castle)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// Only attempt unlinking managed home files for regular castle directories.
|
||||
if castleInfo.Mode()&os.ModeSymlink == 0 {
|
||||
castleHome := filepath.Join(castleRoot, "home")
|
||||
if info, statErr := os.Stat(castleHome); statErr == nil && info.IsDir() {
|
||||
if unlinkErr := a.UnlinkCastle(castle); unlinkErr != nil {
|
||||
return unlinkErr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return os.RemoveAll(castleRoot)
|
||||
}
|
||||
|
||||
func (a *App) Link(castle string) error {
|
||||
if strings.TrimSpace(castle) == "" {
|
||||
castle = "dotfiles"
|
||||
|
||||
Reference in New Issue
Block a user