Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kojirou1994 committed Jan 4, 2024
1 parent 4bde87b commit be36368
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions Sources/video-encoder/VideoEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import SystemUp
@main
struct VideoEncoder: ParsableCommand {

@Flag
var overwrite: Bool = false

@Flag
var removeInput: Bool = false

@Option(name: .shortAndLong)
var encoder: String

Expand All @@ -22,6 +28,17 @@ struct VideoEncoder: ParsableCommand {
var params: [String]

func run() throws {
var status = FileStatus()

if overwrite {
_ = FileSyscalls.unlink(.absolute(.init(output)))
} else {
switch FileSyscalls.fileStatus(.absolute(.init(output)), into: &status) {
case .success: throw Errno.fileExists
case .failure: break
}
}

print("encoder", encoder)
print("input", input)
print("output", output)
Expand All @@ -46,8 +63,19 @@ struct VideoEncoder: ParsableCommand {
command.stdin = .path(path, mode: .readOnly, options: [])
}
command.cwd = cwd
let output = try command.output()
throw ExitCode(output.status.exitStatus)
let statusCode = try command.output().status.exitStatus
if statusCode != 0 {
throw ExitCode(statusCode)
}
switch FileSyscalls.fileStatus(.absolute(.init(output)), into: &status) {
case .success:
if removeInput {
print("encode succeess, remove input")
_ = FileSyscalls.unlink(.absolute(.init(input)))
}
case .failure:
print("encoder exit 0 but output not existed!")
}
}

}

0 comments on commit be36368

Please sign in to comment.