Skip to content

Commit 7bd4d8e

Browse files
committed
a bit more cleanup
handled errors on link.go and unlink.go typo in interactive.go
1 parent 9114589 commit 7bd4d8e

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

cmd/link.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var linkCmd = &cobra.Command{
4040
}
4141
if info.Mode()&os.ModeSymlink != 0 {
4242
internal.LogVerbose(verbose, "%s is already symlinked", destPath)
43-
return fmt.Errorf("Symlink %s already exists", destPath)
43+
return fmt.Errorf("symlink %s already exists", destPath)
4444
}
4545
backupPath := destPath + ".deckbak"
4646
if dryRun {
@@ -49,9 +49,15 @@ var linkCmd = &cobra.Command{
4949
// Check if backup already exists
5050
if _, err := os.Stat(backupPath); err == nil {
5151
internal.LogVerbose(verbose, "Backing up %s -> %s", destPath, backupPath)
52-
os.Rename(destPath, backupPath)
52+
err := os.Rename(destPath, backupPath)
53+
if err != nil {
54+
return err
55+
}
5356
internal.LogVerbose(verbose, "Backed up %s -> %s", destPath, backupPath)
54-
os.Remove(destPath)
57+
err = os.Remove(destPath)
58+
if err != nil {
59+
return err
60+
}
5561
internal.LogVerbose(verbose, "Removed %s", destPath)
5662
}
5763
fmt.Printf("󰑌 Backed up %s to %s\n", destPath, backupPath)

cmd/unlink.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,18 @@ var unlinkCmd = &cobra.Command{
4747
// No backup, ask for confirmation
4848
fmt.Printf("No backup found for %s. You'll lose your config. Delete symlink? [y/N]: ", destPath)
4949
var response string
50-
fmt.Scanln(&response)
50+
_, err := fmt.Scanln(&response)
51+
if err != nil {
52+
return err
53+
}
5154
if response != "y" && response != "Y" {
5255
fmt.Printf("Skipping %s\n", destPath)
5356
continue
5457
}
55-
os.Remove(destPath)
58+
err = os.Remove(destPath)
59+
if err != nil {
60+
return err
61+
}
5662
internal.LogVerbose(verbose, "Removed %s symlink", destPath)
5763
}
5864
return nil

internal/runner/interactive.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"os/exec"
66
)
77

8-
// RunInteractive runs a command with stdio attached so SSH can propmt for passphrase
8+
// RunInteractive runs a command with stdio attached so SSH can prompt for passphrase
99
func RunInteractive(name string, args ...string) error {
1010
cmd := exec.Command(name, args...)
1111
cmd.Env = append(os.Environ(),

0 commit comments

Comments
 (0)