bobashare_admin/
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
//! Admin CLI for managing bobashare

use std::path::PathBuf;

use anyhow::Context;
use bobashare::storage::file::FileBackend;
use clap::{Parser, Subcommand};
use cli::*;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};

pub(crate) mod cli;

#[derive(Debug, Clone, Parser)]
pub(crate) struct Cli {
    #[clap(short, long, value_parser, default_value = "storage/")]
    root: PathBuf,
    #[clap(subcommand)]
    command: Command,
}
#[derive(Debug, Clone, Subcommand)]
pub(crate) enum Command {
    CreateUpload(create::CreateUpload),
    Cleanup(cleanup::Cleanup),
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // TODO: set up logging
    tracing_subscriber::registry()
        .with(tracing_subscriber::EnvFilter::new(
            std::env::var("RUST_LOG").unwrap_or_else(|_| "debug,bobashare=debug".into()),
        ))
        .with(tracing_subscriber::fmt::layer())
        .init();

    let cli = Cli::parse();
    let backend = FileBackend::new(cli.root)
        .await
        .context("error creating file backend")?;

    match cli.command {
        Command::CreateUpload(args) => {
            cli::create::create_upload(backend, args).await?;
        }
        Command::Cleanup(args) => {
            cli::cleanup::cleanup(backend, args).await?;
        }
    };

    Ok(())
}