Skip to content

Commit 234b059

Browse files
ibrahimkteishclaude
andcommitted
Fix: Apply path validation to all custom paths with improved error message
Previously, the validation that checks if the install path is inside `.claude/skills` or `.codex/skills` only ran when using `--path .` or `--path current`. This meant arbitrary paths like `/tmp` could be used. Now: - Any custom path (including `.`, `current`, or absolute paths) is validated - Error message clearly explains both valid options (default vs custom path) - Shows examples of correct usage when validation fails Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 4d1a0c5 commit 234b059

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

Sources/pfw/Install.swift

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,34 @@ struct Install: AsyncParsableCommand {
7474

7575
if isCurrentDirectory {
7676
installURL = URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
77+
} else {
78+
installURL = URL(fileURLWithPath: path ?? tool.defaultInstallPath.path)
79+
}
7780

78-
// Verify the current directory is in the expected location
79-
let currentPath = installURL.path
81+
// Verify the install path is in the expected location (only if custom path provided)
82+
if path != nil {
83+
let installPath = installURL.path
8084
let expectedPattern = ".\(tool.rawValue)/skills"
8185

82-
guard currentPath.contains(expectedPattern) else {
83-
print("Error: Current directory is not in the expected location.")
84-
print("Expected to be inside: ~/.\(tool.rawValue)/skills/")
85-
print("Current directory: \(currentPath)")
86+
guard installPath.contains(expectedPattern) else {
87+
print("Error: Install path is not in the expected location.")
88+
print("")
89+
print("The install path must contain '.\(tool.rawValue)/skills' in it.")
90+
print("")
91+
print("Valid options:")
92+
print(" 1. Use default path: pfw install --tool \(tool.rawValue)")
93+
print(" Installs to: ~/.\(tool.rawValue)/skills/the-point-free-way")
94+
print("")
95+
print(" 2. Use custom path ending with '.\(tool.rawValue)/skills':")
96+
print(" pfw install --tool \(tool.rawValue) --path /your/project/.\(tool.rawValue)/skills")
97+
print("")
98+
print("Current install path: \(installPath)")
8699
throw ExitCode.failure
87100
}
88101

89-
// Ask for confirmation
90-
print("You are about to install into the current directory:")
91-
print(" \(currentPath)")
102+
// Ask for confirmation when using custom path
103+
print("You are about to install into:")
104+
print(" \(installPath)")
92105
print("\nThis will merge new skills with existing ones without removing current files.")
93106
print("Continue? (yes/no): ", terminator: "")
94107

@@ -97,8 +110,6 @@ struct Install: AsyncParsableCommand {
97110
print("Installation cancelled.")
98111
throw ExitCode.success
99112
}
100-
} else {
101-
installURL = URL(fileURLWithPath: path ?? tool.defaultInstallPath.path)
102113
}
103114

104115
// Always merge - never remove existing files

0 commit comments

Comments
 (0)