arnaucube
arnaucube/link2epub-rsPublic Self-hosted repository
link2epub-rs/src/main.rs
src/main.rsRaw
 1use anyhow::Result;
 2use clap::{Parser, ValueEnum};
 3use link2epub::{convert, Format, Options};
 4
 5const VERSION: &str = "v0_20260914";
 6
 7#[derive(Debug, Parser)]
 8#[command(version, about)]
 9struct Cli {
10    /// url of the article to download
11    url: String,
12
13    /// output type: epub or mobi
14    #[arg(short = 't', value_enum, default_value_t = OutputFormat::Epub)]
15    output_type: OutputFormat,
16}
17
18#[derive(Clone, Copy, Debug, ValueEnum)]
19enum OutputFormat {
20    Epub,
21    Mobi,
22}
23
24impl From<OutputFormat> for Format {
25    fn from(value: OutputFormat) -> Self {
26        match value {
27            OutputFormat::Epub => Self::Epub,
28            OutputFormat::Mobi => Self::Mobi,
29        }
30    }
31}
32
33fn main() -> Result<()> {
34    println!("link2epub (rs) version {}", VERSION);
35    let cli = Cli::parse();
36    let output = convert(Options {
37        url: cli.url,
38        format: cli.output_type.into(),
39    })?;
40    println!("Created {}", output.display());
41    Ok(())
42}