1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use clap::Parser;
use lottieconv::Converter;
use rlottie::Animation;
use std::{fs::File, io::Write, path::PathBuf};
#[derive(Parser)]
struct Args {
#[clap(name = "lottieFileName")]
lottie_file_name: PathBuf,
#[clap(short = 'o', long = "out", name = "output")]
output: Option<PathBuf>
}
fn main() {
let args = Args::parse();
let path = args.lottie_file_name;
println!("Converting file {} ...", path.display());
let player = Animation::from_file(&path).expect("Failed to open file");
let webp_path = match args.output {
Some(path) => path,
None => {
let file_stem = path.file_stem().expect("Missing file stem");
let mut webp_path = path.clone();
let mut webp_file_name = file_stem.to_owned();
webp_file_name.push(".webp");
webp_path.set_file_name(webp_file_name);
webp_path
}
};
let webp = Converter::new(player)
.webp()
.and_then(Converter::convert)
.expect("Conversion failed");
let mut out = File::create(&webp_path).expect("Failed to create output file");
out.write_all(&webp).expect("Failed to write output file");
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn verify_cli() {
use clap::CommandFactory;
Args::command().debug_assert()
}
}