add cli
This commit is contained in:
parent
8e98a67229
commit
afe538bb56
3 changed files with 146 additions and 18 deletions
100
Cargo.lock
generated
100
Cargo.lock
generated
|
@ -222,6 +222,45 @@ dependencies = [
|
||||||
"generic-array",
|
"generic-array",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap"
|
||||||
|
version = "3.1.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7c167e37342afc5f33fd87bbc870cedd020d2a6dffa05d45ccd9241fbdd146db"
|
||||||
|
dependencies = [
|
||||||
|
"atty",
|
||||||
|
"bitflags",
|
||||||
|
"clap_derive",
|
||||||
|
"clap_lex",
|
||||||
|
"indexmap",
|
||||||
|
"lazy_static",
|
||||||
|
"strsim",
|
||||||
|
"termcolor",
|
||||||
|
"textwrap",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_derive"
|
||||||
|
version = "3.1.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a3aab4734e083b809aaf5794e14e756d1c798d2c69c7f7de7a09a2f5214993c1"
|
||||||
|
dependencies = [
|
||||||
|
"heck",
|
||||||
|
"proc-macro-error",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_lex"
|
||||||
|
version = "0.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "189ddd3b5d32a70b35e7686054371742a937b0d99128e76dde6340210e966669"
|
||||||
|
dependencies = [
|
||||||
|
"os_str_bytes",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "constant_time_eq"
|
name = "constant_time_eq"
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
|
@ -911,6 +950,7 @@ version = "0.1.0-dev"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.13.0",
|
"base64 0.13.0",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"clap",
|
||||||
"diesel",
|
"diesel",
|
||||||
"diesel-derive-enum",
|
"diesel-derive-enum",
|
||||||
"djangohashers",
|
"djangohashers",
|
||||||
|
@ -998,6 +1038,12 @@ version = "0.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
|
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "os_str_bytes"
|
||||||
|
version = "6.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking_lot"
|
name = "parking_lot"
|
||||||
version = "0.11.2"
|
version = "0.11.2"
|
||||||
|
@ -1122,6 +1168,30 @@ version = "0.2.16"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
|
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro-error"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro-error-attr",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro-error-attr"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"version_check",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.37"
|
version = "1.0.37"
|
||||||
|
@ -1551,6 +1621,12 @@ dependencies = [
|
||||||
"loom",
|
"loom",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strsim"
|
||||||
|
version = "0.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "subtle"
|
name = "subtle"
|
||||||
version = "2.4.1"
|
version = "2.4.1"
|
||||||
|
@ -1582,6 +1658,21 @@ dependencies = [
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "termcolor"
|
||||||
|
version = "1.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-util",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "textwrap"
|
||||||
|
version = "0.15.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
version = "1.0.30"
|
version = "1.0.30"
|
||||||
|
@ -2055,6 +2146,15 @@ version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "winapi-util"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
||||||
|
dependencies = [
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi-x86_64-pc-windows-gnu"
|
name = "winapi-x86_64-pc-windows-gnu"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
|
|
|
@ -24,3 +24,4 @@ chrono = { version = "0.4", features = ["serde"] }
|
||||||
humantime = "2.1.0"
|
humantime = "2.1.0"
|
||||||
tokio = "1"
|
tokio = "1"
|
||||||
figment = { version = "0.10.6", features = ["toml", "env"] }
|
figment = { version = "0.10.6", features = ["toml", "env"] }
|
||||||
|
clap = {version = "3", features = ["derive", "cargo"]}
|
||||||
|
|
63
src/main.rs
63
src/main.rs
|
@ -12,19 +12,53 @@ mod dns;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
||||||
use figment::{Figment, Profile, providers::{Format, Toml, Env}};
|
use figment::{Figment, Profile, providers::{Format, Toml, Env}};
|
||||||
|
use rocket_sync_db_pools::database;
|
||||||
|
use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
use routes::users::*;
|
use routes::users::*;
|
||||||
use routes::zones::*;
|
use routes::zones::*;
|
||||||
use rocket_sync_db_pools::database;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[database("sqlite")]
|
#[database("sqlite")]
|
||||||
pub struct DbConn(diesel::SqliteConnection);
|
pub struct DbConn(diesel::SqliteConnection);
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
#[clap(author, version, about, long_about = None)]
|
||||||
|
#[clap(propagate_version = true)]
|
||||||
|
struct Nomilo {
|
||||||
|
#[clap(subcommand)]
|
||||||
|
command: Command
|
||||||
|
}
|
||||||
|
|
||||||
#[launch]
|
#[derive(Subcommand)]
|
||||||
async fn rocket() -> _ {
|
enum Command {
|
||||||
|
/// Lauch web server
|
||||||
|
Serve,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn serve(figment: Figment, app_config: config::Config) {
|
||||||
|
rocket::async_main(async move {
|
||||||
|
let _res = rocket::custom(figment)
|
||||||
|
.manage(app_config)
|
||||||
|
.attach(DbConn::fairing())
|
||||||
|
.mount("/api/v1", routes![
|
||||||
|
get_zone_records,
|
||||||
|
create_zone_records,
|
||||||
|
update_zone_records,
|
||||||
|
delete_zone_records,
|
||||||
|
get_zones,
|
||||||
|
create_zone,
|
||||||
|
add_member_to_zone,
|
||||||
|
create_auth_token,
|
||||||
|
create_user,
|
||||||
|
])
|
||||||
|
.launch().await;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn main() {
|
||||||
let figment = Figment::from(rocket::Config::default())
|
let figment = Figment::from(rocket::Config::default())
|
||||||
.merge(Toml::file(Env::var_or("NOMILO_CONFIG", "nomilo.toml")).nested())
|
.merge(Toml::file(Env::var_or("NOMILO_CONFIG", "nomilo.toml")).nested())
|
||||||
.merge(Env::prefixed("NOMILO_").ignore(&["PROFILE"]).global())
|
.merge(Env::prefixed("NOMILO_").ignore(&["PROFILE"]).global())
|
||||||
|
@ -38,18 +72,11 @@ async fn rocket() -> _ {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
rocket::custom(figment)
|
let nomilo = Nomilo::parse();
|
||||||
.manage(app_config)
|
|
||||||
.attach(DbConn::fairing())
|
match nomilo.command {
|
||||||
.mount("/api/v1", routes![
|
Command::Serve => serve(figment, app_config),
|
||||||
get_zone_records,
|
};
|
||||||
create_zone_records,
|
|
||||||
update_zone_records,
|
|
||||||
delete_zone_records,
|
|
||||||
get_zones,
|
|
||||||
create_zone,
|
|
||||||
add_member_to_zone,
|
|
||||||
create_auth_token,
|
|
||||||
create_user,
|
|
||||||
])
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue