Skip to content

Commit 267d6ef

Browse files
Skip file creation because the file exists.
1 parent 9b3749d commit 267d6ef

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Sources/AtCoderCLI/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import SwiftShell
55
struct Command: ParsableCommand {
66
static var configuration = CommandConfiguration(
77
abstract: "AtCoder CLI for Swift.",
8-
version: "1.0.8",
8+
version: "1.0.9",
99
subcommands: [
1010
New.self,
1111
Submit.self,

Sources/AtCoderLibrary/Command/New/Generator/Generator.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ extension Generator {
1111
if let directory = directory {
1212
try FileManager.default.createDirectory(atPath: directory, withIntermediateDirectories: true)
1313
}
14-
try source.write(toFile: "\(directory ?? ".")/\(fileName)", atomically: true, encoding: .utf8)
14+
let filePath = "\(directory ?? ".")/\(fileName)"
15+
guard !FileManager.default.fileExists(atPath: filePath) else {
16+
print("Skip file creation because the file exists.", "path: ", filePath)
17+
return
18+
}
19+
try source.write(toFile: filePath, atomically: true, encoding: .utf8)
1520
}
1621
}

0 commit comments

Comments
 (0)