Skip to content

Commit 2347486

Browse files
committed
feat(video-only): add command line parameter --video-only | -M
- relates to #71, command line parameter for video only - introduce the new cli parameter - refactor main a bit
1 parent d826c98 commit 2347486

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

src/cli.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ pub fn launch<'a>() -> ArgMatches<'a> {
2929
.required(false)
3030
.help("Generates additionally to the gif a mp4 video of the recording")
3131
)
32+
.arg(
33+
Arg::with_name("video-only")
34+
.takes_value(false)
35+
.short("M")
36+
.long("video-only")
37+
.required(false)
38+
.conflicts_with("video")
39+
.help("Generates only a mp4 video and not gif")
40+
)
3241
.arg(
3342
Arg::with_name("decor")
3443
.takes_value(true)

src/main.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,17 @@ fn main() -> Result<()> {
7777
api.calibrate(win_id)?;
7878

7979
let force_natural = args.is_present("natural-mode");
80-
let with_video = args.is_present("video");
80+
let should_generate_gif = !args.is_present("video-only");
81+
let should_generate_video = args.is_present("video") || args.is_present("video-only");
8182
let (start_delay, end_delay) = (
8283
parse_delay(args.value_of("start-pause"), "start-pause")?,
8384
parse_delay(args.value_of("end-pause"), "end-pause")?,
8485
);
8586

86-
check_for_gif()?;
87-
if with_video {
87+
if should_generate_gif {
88+
check_for_gif()?;
89+
}
90+
if should_generate_video {
8891
check_for_mp4()?;
8992
}
9093

@@ -155,24 +158,26 @@ fn main() -> Result<()> {
155158
}
156159

157160
let target = target_file();
158-
let gif_target = format!("{}.{}", target, "gif");
159-
let mut time = prof! {
160-
generate_gif(
161-
&time_codes.lock().unwrap(),
162-
tempdir.lock().unwrap().borrow(),
163-
&gif_target,
164-
start_delay,
165-
end_delay
166-
)?;
167-
};
161+
let mut time = Duration::default();
162+
163+
if should_generate_gif {
164+
time += prof! {
165+
generate_gif(
166+
&time_codes.lock().unwrap(),
167+
tempdir.lock().unwrap().borrow(),
168+
&format!("{}.{}", target, "gif"),
169+
start_delay,
170+
end_delay
171+
)?;
172+
};
173+
}
168174

169-
if with_video {
170-
let mp4_target = format!("{}.{}", target, "mp4");
175+
if should_generate_video {
171176
time += prof! {
172177
generate_mp4(
173178
&time_codes.lock().unwrap(),
174179
tempdir.lock().unwrap().borrow(),
175-
&mp4_target,
180+
&format!("{}.{}", target, "mp4"),
176181
)?;
177182
}
178183
}

0 commit comments

Comments
 (0)