aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 3d0eee54ff715252dbe8570888b6b32817da1ad2 (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
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
62
63
64
65
#![deny(clippy::all)]
#![warn(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]
#![feature(file_create_new)]
#![feature(map_try_insert)]
#![feature(result_option_inspect)]

mod client;
mod common;
mod index;
mod server;

// use fs::FileSystem;
// use index::Index;
use client::fs::FileSystem;
use serde::{Deserialize, Serialize};
use server::Server;
use std::env;

const CONFIG: &str = "carton.toml";

#[derive(Serialize, Deserialize)]
struct Config {
    server: server::Config,
    client: client::Config,
}

fn main() {
    let mut logger = env_logger::Builder::from_default_env();
    logger.filter(None, log::LevelFilter::Debug).init();

    // Config
    let config: Config = toml::from_str(
        &std::fs::read_to_string(CONFIG).expect("Missing config file at {CONFIG:?}"),
    )
    .expect("Invalid config file at {CONFIG:?}");

    // Args
    let args: Vec<String> = env::args().collect();

    if args.len() < 2 {
        println!("Missing command for carton.");
        return;
    }

    match args[1].as_str() {
        // "index-scan" => cmd_index_scan(&args[2..]),
        // "reindex" => cmd_index_scan(&args[2..]),
        "fs-mount" => cmd_fs_mount(config, &args[2..]),
        _ => todo!(),
    }
}

// fn cmd_index_scan(args: &[String]) {
//     index::spawn_scan(Path::new(ROOT));
// }

fn cmd_fs_mount(config: Config, _args: &[String]) {
    let server = Server::new(&config.server).expect("Couldn't initialize server.");

    // let index = Index::new(Path::new(ROOT)).unwrap();

    let fs = FileSystem::new(server);
    fs.mount(&config.client.fs.mountpoint).unwrap();
}