Skip to content

Commit 65a2721

Browse files
authored
Output to a new folder (#6)
1 parent fe44731 commit 65a2721

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

Sources/ImageCramCLI/CommandLineError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extension CommandLineError: CustomStringConvertible {
2222
case .apiKeyFileInvalid:
2323
return "API key file is missing, please try re-running, then updating ImageCram and then reporting the issue on GitHub if it persists."
2424
case let .failedToMoveFile(from, to):
25-
return "Failed to remove file from \(from) to \(to)"
25+
return "Failed to move file from \(from) to \(to)"
2626
case let .invalidInputFile(path):
2727
return "Cannot read input file at \(path)"
2828
case let .invalidOutput(path):

Sources/ImageCramCLI/FileMover.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ struct FileMover {
2323
guard let outputPath = outputPath else {
2424
return inputFile.url
2525
}
26-
guard let outputFolder = try? Folder(path: outputPath) else {
27-
return URL(fileURLWithPath: outputPath)
26+
let outputUrl = URL(fileURLWithPath: outputPath)
27+
if outputUrl.pathExtension.isEmpty {
28+
try FileManager.default.createDirectory(at: outputUrl, withIntermediateDirectories: true, attributes: [:])
29+
return outputUrl.appendingPathComponent(inputFile.name)
2830
}
29-
return URL(fileURLWithPath: outputFolder.path + "/" + inputFile.name)
31+
return outputUrl
3032
}
3133
}

Sources/ImageCramTasks/Shell.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ struct ShellError: Error, CustomStringConvertible {
99
}
1010
}
1111

12-
func runShell(_ command: String, with arguments: [String] = [], continueOnError: Bool = false) throws {
12+
func runShell(_ command: String, continueOnError: Bool = false) throws {
1313
do {
1414
try shellOut(
1515
to: command,
16-
arguments: arguments,
1716
outputHandle: .standardOutput,
1817
errorHandle: .standardError
1918
)

0 commit comments

Comments
 (0)