Skip to content

Commit e3d3648

Browse files
author
xenodium
committed
Try to use output extensions to determine media type
1 parent 8335f5a commit e3d3648

1 file changed

Lines changed: 41 additions & 2 deletions

File tree

Sources/main.swift

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ struct RecordCommand: ParsableCommand {
7878
Darwin.exit(1)
7979
}
8080

81+
if mov || gif {
82+
print("Error: can't use --simultaneously with --mov or --gif")
83+
Darwin.exit(1)
84+
}
85+
86+
if let output = output,
87+
URL(fileURLWithPath: output).pathExtension != "png"
88+
{
89+
print("Error: --png not compatible with \(output)")
90+
Darwin.exit(1)
91+
}
92+
8193
let identifier = resolveWindowID(windowIdentifier)
8294
if let output = output {
8395
recorder = WindowRecorder(.png, for: identifier, URL(fileURLWithPath: output))
@@ -101,15 +113,42 @@ struct RecordCommand: ParsableCommand {
101113
}
102114

103115
if mov {
116+
if let output = output,
117+
URL(fileURLWithPath: output).pathExtension != "mov"
118+
{
119+
print("Error: --mov not compatible with \(output)")
120+
Darwin.exit(1)
121+
}
104122
return WindowRecorder.MediaType.mov
105123
}
106124

107125
if gif {
126+
if let output = output,
127+
URL(fileURLWithPath: output).pathExtension != "gif"
128+
{
129+
print("Error: --gif not compatible with \(output)")
130+
Darwin.exit(1)
131+
}
108132
return WindowRecorder.MediaType.gif
109133
}
110134

111-
// Default to mov otherwise
112-
return WindowRecorder.MediaType.mov
135+
guard let output = output else {
136+
// Default to mov otherwise
137+
return WindowRecorder.MediaType.mov
138+
}
139+
140+
let ext = URL(fileURLWithPath: output).pathExtension
141+
142+
if ext == "mov" {
143+
return WindowRecorder.MediaType.mov
144+
}
145+
146+
if ext == "gif" {
147+
return WindowRecorder.MediaType.gif
148+
}
149+
150+
print("Error: Unsupported extension .\(ext)")
151+
Darwin.exit(1)
113152
}()
114153

115154
let identifier = resolveWindowID(windowIdentifier)

0 commit comments

Comments
 (0)