main: Add arguments and the respective parsing
Signed-off-by: Gunwant Jain <mail@wantguns.dev>
This commit is contained in:
36
src/main.rs
36
src/main.rs
@@ -1,14 +1,50 @@
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
use std::{fs, net::IpAddr, path::PathBuf};
|
||||
|
||||
use clap::Parser;
|
||||
use rocket::shield::{NoSniff, Shield};
|
||||
use rocket_dyn_templates::Template;
|
||||
|
||||
mod models;
|
||||
mod routes;
|
||||
|
||||
/// A minimal, opinionated pastebin
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(author, version, about, long_about=None)]
|
||||
pub struct Args {
|
||||
/// Path to the uploads folder
|
||||
#[clap(short, long, default_value = "./upload")]
|
||||
upload: std::path::PathBuf,
|
||||
|
||||
/// Port on which the webserver runs
|
||||
#[clap(short, long, default_value_t = 6162)]
|
||||
port: u16,
|
||||
|
||||
/// Address on which the webserver runs
|
||||
#[clap(short, long, default_value = "0.0.0.0")]
|
||||
address: IpAddr,
|
||||
|
||||
/// Binary uploads file size limit (in MiB)
|
||||
#[clap(short, long, default_value_t = 100)]
|
||||
binary_upload_limit: i32,
|
||||
}
|
||||
|
||||
pub fn get_parsed_args() -> Args {
|
||||
Args::parse()
|
||||
}
|
||||
|
||||
pub fn get_upload_dir() -> PathBuf {
|
||||
get_parsed_args().upload
|
||||
}
|
||||
|
||||
#[launch]
|
||||
fn rocket() -> _ {
|
||||
let shield = Shield::default().disable::<NoSniff>();
|
||||
let args = get_parsed_args();
|
||||
|
||||
// create the upload directory, if not already created
|
||||
fs::create_dir_all(args.upload).expect("Could not create the upload directory");
|
||||
|
||||
rocket::build()
|
||||
.mount(
|
||||
|
||||
Reference in New Issue
Block a user