Skip to content

Commit 57caa0a

Browse files
authored
feat(#105): add support configuring output (#107)
- fixes #105 - introduce `-o | --output` argument that accepts the file basename without any extension - the logic with checking for file existence and adding incrementing numbers remains as is - fix(ci:deb): fix the ci deb builder
1 parent 524a995 commit 57caa0a

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
steps:
9090
- uses: actions/checkout@v2
9191
- name: build .deb file
92-
uses: sassman/rust-deb-builder@v1.57.0
92+
uses: sassman/rust-deb-builder@v1
9393
- name: Archive deb artifact
9494
uses: actions/upload-artifact@v2
9595
with:

src/cli.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ pub fn launch() -> ArgMatches {
102102
.long("start-pause")
103103
.help("to specify the pause time at the start of the animation, that time the gif will show the first frame"),
104104
)
105+
.arg(
106+
Arg::new("file")
107+
.takes_value(true)
108+
.required(false)
109+
.short('o')
110+
.long("output")
111+
.default_value("t-rec")
112+
.help("to specify the output file (without extension)"),
113+
)
105114
.arg(
106115
Arg::new("program")
107116
.value_name("shell or program to launch")

src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::generators::{check_for_gif, check_for_mp4, generate_gif, generate_mp4
2828
use crate::tips::show_tip;
2929

3030
use crate::capture::capture_thread;
31-
use crate::utils::{sub_shell_thread, target_file};
31+
use crate::utils::{sub_shell_thread, target_file, DEFAULT_EXT, MOVIE_EXT};
3232
use anyhow::{bail, Context};
3333
use clap::ArgMatches;
3434
use image::FlatSamples;
@@ -158,15 +158,15 @@ fn main() -> Result<()> {
158158
)
159159
}
160160

161-
let target = target_file();
161+
let target = target_file(args.value_of("file").unwrap());
162162
let mut time = Duration::default();
163163

164164
if should_generate_gif {
165165
time += prof! {
166166
generate_gif(
167167
&time_codes.lock().unwrap(),
168168
tempdir.lock().unwrap().borrow(),
169-
&format!("{}.{}", target, "gif"),
169+
&format!("{}.{}", target, DEFAULT_EXT),
170170
start_delay,
171171
end_delay
172172
)?;
@@ -178,7 +178,7 @@ fn main() -> Result<()> {
178178
generate_mp4(
179179
&time_codes.lock().unwrap(),
180180
tempdir.lock().unwrap().borrow(),
181-
&format!("{}.{}", target, "mp4"),
181+
&format!("{}.{}", target, MOVIE_EXT),
182182
)?;
183183
}
184184
}

src/utils.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ use anyhow::{Context, Result};
22
use std::ffi::OsStr;
33
use std::process::{Command, ExitStatus};
44

5+
pub const DEFAULT_EXT: &str = "gif";
6+
pub const MOVIE_EXT: &str = "mp4";
7+
58
/// encapsulate the file naming convention
69
pub fn file_name_for(tc: &u128, ext: &str) -> String {
710
format!("t-rec-frame-{:09}.{}", tc, ext)
@@ -20,17 +23,16 @@ pub fn sub_shell_thread<T: AsRef<OsStr> + Clone>(program: T) -> Result<ExitStatu
2023
/// returns a new filename that does not yet exists.
2124
/// Note: returns without extension, but checks with extension
2225
/// like `t-rec` or `t-rec_1`
23-
pub fn target_file() -> String {
26+
pub fn target_file(basename: impl AsRef<str>) -> String {
27+
let basename = basename.as_ref();
2428
let mut suffix = "".to_string();
25-
let default_ext = "gif";
26-
let movie_ext = "mp4";
2729
let mut i = 0;
28-
while std::path::Path::new(format!("t-rec{}.{}", suffix, default_ext).as_str()).exists()
29-
|| std::path::Path::new(format!("t-rec{}.{}", suffix, movie_ext).as_str()).exists()
30+
while std::path::Path::new(format!("{basename}{suffix}.{DEFAULT_EXT}").as_str()).exists()
31+
|| std::path::Path::new(format!("{basename}{suffix}.{MOVIE_EXT}").as_str()).exists()
3032
{
3133
i += 1;
3234
suffix = format!("_{}", i).to_string();
3335
}
3436

35-
format!("t-rec{}", suffix)
37+
format!("{basename}{suffix}")
3638
}

0 commit comments

Comments
 (0)