aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 223fd24e1bc0e841ad5072b4473fdf96592fae02 (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
35
use std::env;
use std::process::ExitCode;

mod cleanup;
mod render;
mod serve;

fn main() -> ExitCode {
    let args: Vec<String> = env::args().collect();
    let command = args.get(1).map(String::as_str);

    match command {
        None => serve::run(),
        Some("--run") => {
            if let Some(dir) = args.get(2) {
                cleanup::run(dir)
            } else {
                eprintln!("estampa: --run requires a directory argument");
                print_usage();
                ExitCode::from(2)
            }
        }
        Some(other) => {
            eprintln!("estampa: unknown argument '{other}'");
            print_usage();
            ExitCode::from(2)
        }
    }
}

fn print_usage() {
    eprintln!("usage:");
    eprintln!("  estampa                    serve a paste via CGI (DOCUMENT_ROOT + DOCUMENT_URI)");
    eprintln!("  estampa --run <directory>  delete files older than one week");
}