Skip to content

Commit

Permalink
Create remove command for templates
Browse files Browse the repository at this point in the history
  • Loading branch information
josefdolezal committed Aug 26, 2018
1 parent bc2f7dc commit f8414dd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Sources/xcman/XCManTemplatesTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,12 @@ let templatesCommand = Group {
// Print each templates set one by one
templates.forEach { print($0) }
}

$0.command("remove",
VariadicArgument<String>("name", description: "Name of the templates set to be deleted"),
description: "Removes installed templates from Xcode"
) { names in
// Remove all sets listed by user
try names.forEach { try templatesManager.delete(templatesSet: $0) }
}
}
17 changes: 17 additions & 0 deletions Sources/xcmanlib/TemplatesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,21 @@ public final class TemplatesManager {
// Map to folders name
.map { $0.lastPathComponent }
}

public func delete(templatesSet: String) throws {
// URL of templates set being deleted
let url = FileManager.default.homeDirectoryUrl.appendingPathComponent(UserDataType.templates.xcodePath(for: templatesSet), isDirectory: true)

// Throw an error if directory does not exists
if !FileManager.default.fileExists(atPath: url.path) {
throw UserDataError.couldNotReadRepositoryContent(url)
}

// Remove the directory
do {
try FileManager.default.removeItem(at: url)
} catch {
throw UserDataError.couldNotRemoveExistingUserData(url, error)
}
}
}

0 comments on commit f8414dd

Please sign in to comment.