From 9b4246a07818b09abf728962f8e975e27af75b03 Mon Sep 17 00:00:00 2001 From: erik Date: Tue, 8 Jun 2021 13:18:56 +0000 Subject: [PATCH] Add structopt Co-authored-by: Elias Schriefer --- Cargo.lock | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/main.rs | 16 ++++++++-- 3 files changed, 103 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f2cdd4e..65f9511 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -41,6 +41,15 @@ dependencies = [ "alloc-no-stdlib", ] +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +dependencies = [ + "winapi 0.3.9", +] + [[package]] name = "anyhow" version = "1.0.40" @@ -258,6 +267,22 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "clap" +version = "2.33.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim", + "term_size", + "textwrap", + "unicode-width", + "vec_map", +] + [[package]] name = "colored" version = "1.9.3" @@ -1182,6 +1207,7 @@ dependencies = [ "juniper-from-schema", "juniper_warp", "sqlx", + "structopt", "warp 0.3.1", ] @@ -1900,6 +1926,36 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + +[[package]] +name = "structopt" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5277acd7ee46e63e5168a80734c9f6ee81b1367a7d8772a2d765df2a3705d28c" +dependencies = [ + "clap", + "lazy_static", + "structopt-derive", +] + +[[package]] +name = "structopt-derive" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ba9cdfda491b814720b6b06e0cac513d922fc407582032e8706e9f137976f90" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "syn" version = "1.0.69" @@ -1931,6 +1987,26 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "term_size" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9" +dependencies = [ + "libc", + "winapi 0.3.9", +] + +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "term_size", + "unicode-width", +] + [[package]] name = "thiserror" version = "1.0.24" @@ -2191,6 +2267,12 @@ version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" +[[package]] +name = "unicode-width" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" + [[package]] name = "unicode-xid" version = "0.2.1" @@ -2254,6 +2336,12 @@ version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "025ce40a007e1907e58d5bc1a594def78e5573bb0b1160bc389634e8f12e4faa" +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + [[package]] name = "version_check" version = "0.9.3" diff --git a/Cargo.toml b/Cargo.toml index 94db041..522cba5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ juniper_warp = "^0.6" juniper-from-schema = { git = "https://github.com/davidpdrsn/juniper-from-schema" } sqlx = { version = "^0.5", features = ["runtime-tokio-native-tls"] } warp = { version = "^0.3", default-features = false, features = ["compression", "tls"] } +structopt = { version = "^0.3", features = ["wrap_help"] } [features] default = ["sqlite"] diff --git a/src/main.rs b/src/main.rs index e7a11a9..0411239 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,15 @@ -fn main() { - println!("Hello, world!"); +use structopt::StructOpt; +use std::path::PathBuf; + +#[derive(Debug, StructOpt)] +struct Options { + #[structopt(short, long, default_value = "/etc/noise-server/config.toml")] + config: PathBuf, + + #[structopt(short, long, default_value = "/var/lib/noise-server/noise-server.sqlite")] + database_path: PathBuf, +} + +fn main() { + let options = Options::from_args(); }