aboutsummaryrefslogtreecommitdiff
path: root/tools/src/bin/create_item.rs
blob: eb5b3a9f39c54bb0dd1d7d0cae98dd00f315fbc0 (plain)
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
use std::{fs::File, io::Write, path::PathBuf};

use clap::Parser;
use jellycommon::ItemInfo;

#[derive(Parser)]
struct Args {
    #[clap(short = 'I', long)]
    item: PathBuf,
    #[clap(short = 'd', long)]
    dry: bool,
    #[clap(short, long)]
    title: String,
}

fn main() -> anyhow::Result<()> {
    let args = Args::parse();

    let iteminfo = ItemInfo {
        title: args.title,
        path: String::new(),
        duration: 0.0,
        tracks: Default::default(),
    };

    let k = serde_json::to_string_pretty(&iteminfo)?;
    if args.dry {
        println!("{k}")
    } else {
        let mut f = File::create(args.item)?;
        f.write_all(k.as_bytes())?;
    }
    Ok(())
}