-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
61 lines (50 loc) · 1.66 KB
/
main.rs
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
53
54
55
56
57
58
59
60
61
mod ffmpeg;
mod server;
// mod span;
use std::{env::current_dir, fs, io};
use ffmpeg::ErrorKind as FfmpegError;
use tracing::Level;
use tracing_subscriber::fmt::format::FmtSpan;
type CommandResult<T = ()> = Result<T, FfmpegError>;
async fn handle_serve(matches: &clap::ArgMatches<'_>) -> CommandResult {
match matches.value_of("INPUT") {
Some(file_path) => {
server::FrameServer::new(file_path.to_string())?
.serve()
.await;
Ok(())
}
None => Err(FfmpegError::ArgumentError),
}
}
#[tokio::main]
async fn main() -> CommandResult {
use clap::{App, Arg, SubCommand};
let subscriber = tracing_subscriber::FmtSubscriber::builder()
.with_writer(write_to_log)
.with_span_events(FmtSpan::CLOSE)
.with_target(false)
.with_max_level(Level::TRACE)
.with_level(false)
.with_line_number(true)
.finish();
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
let input_arg = &Arg::with_name("INPUT")
.required(true)
.help("Sets the input file to use");
let app_m = App::new("frm")
.subcommand(SubCommand::with_name("serve").arg(input_arg))
.get_matches();
match app_m.subcommand() {
("serve", Some(sub_m)) => handle_serve(sub_m).await,
_ => Err(FfmpegError::ArgumentError),
}
}
const LOG_PATH: &str = "development.log";
fn write_to_log() -> impl io::Write {
let pwd = current_dir().expect("couldn't get current dir");
fs::File::options()
.append(true)
.open(pwd.join(LOG_PATH))
.expect("failed to create file")
}