Skip to content

Commit

Permalink
Try to use output extensions to determine media type
Browse files Browse the repository at this point in the history
  • Loading branch information
xenodium committed Apr 15, 2023
1 parent 8335f5a commit e3d3648
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions Sources/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ struct RecordCommand: ParsableCommand {
Darwin.exit(1)
}

if mov || gif {
print("Error: can't use --simultaneously with --mov or --gif")
Darwin.exit(1)
}

if let output = output,
URL(fileURLWithPath: output).pathExtension != "png"
{
print("Error: --png not compatible with \(output)")
Darwin.exit(1)
}

let identifier = resolveWindowID(windowIdentifier)
if let output = output {
recorder = WindowRecorder(.png, for: identifier, URL(fileURLWithPath: output))
Expand All @@ -101,15 +113,42 @@ struct RecordCommand: ParsableCommand {
}

if mov {
if let output = output,
URL(fileURLWithPath: output).pathExtension != "mov"
{
print("Error: --mov not compatible with \(output)")
Darwin.exit(1)
}
return WindowRecorder.MediaType.mov
}

if gif {
if let output = output,
URL(fileURLWithPath: output).pathExtension != "gif"
{
print("Error: --gif not compatible with \(output)")
Darwin.exit(1)
}
return WindowRecorder.MediaType.gif
}

// Default to mov otherwise
return WindowRecorder.MediaType.mov
guard let output = output else {
// Default to mov otherwise
return WindowRecorder.MediaType.mov
}

let ext = URL(fileURLWithPath: output).pathExtension

if ext == "mov" {
return WindowRecorder.MediaType.mov
}

if ext == "gif" {
return WindowRecorder.MediaType.gif
}

print("Error: Unsupported extension .\(ext)")
Darwin.exit(1)
}()

let identifier = resolveWindowID(windowIdentifier)
Expand Down

0 comments on commit e3d3648

Please sign in to comment.