Add methods to parse cli arguments

next
Sayan Nandan 4 years ago
parent 0690be4d4e
commit 86d15120e4
No known key found for this signature in database
GPG Key ID: C31EFD7DDA12AEE0

70
Cargo.lock generated

@ -9,12 +9,32 @@ dependencies = [
"memchr",
]
[[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 = "arc-swap"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d25d88fd6b8041580a654f9d0c581a047baee2b3efee13275f2fc392fc75034"
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi 0.3.9",
]
[[package]]
name = "bincode"
version = "1.3.1"
@ -49,6 +69,22 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[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",
"textwrap",
"unicode-width",
"vec_map",
"yaml-rust",
]
[[package]]
name = "cloudabi"
version = "0.1.0"
@ -448,6 +484,12 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "strsim"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "syn"
version = "1.0.34"
@ -465,6 +507,7 @@ version = "0.4.0"
dependencies = [
"bincode",
"bytes",
"clap",
"lazy_static",
"libtdb",
"parking_lot",
@ -482,6 +525,15 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "textwrap"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
dependencies = [
"unicode-width",
]
[[package]]
name = "thread_local"
version = "1.0.1"
@ -548,12 +600,24 @@ dependencies = [
"tokio",
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "wasi"
version = "0.9.0+wasi-snapshot-preview1"
@ -612,3 +676,9 @@ dependencies = [
"winapi 0.2.8",
"winapi-build",
]
[[package]]
name = "yaml-rust"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e66366e18dc58b46801afbf2ca7661a9f59cc8c5962c29892b6039b4f86fa992"

@ -15,5 +15,6 @@ parking_lot = "0.11.0"
lazy_static = "1.4.0"
serde = {version = "1.0.115", features= ["derive"]}
toml = "0.5.6"
clap = {version = "2.33.3", features=["yaml"]}
[dev-dependencies]
tokio = { version = "0.2", features = ["test-util"] }

@ -0,0 +1,32 @@
#
# Created on Tue Sep 01 2020
#
# This file is a part of TerrabaseDB
# Copyright (c) 2020, Sayan Nandan <ohsayan at outlook dot com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#
name: TerrabaseDB Server
version: 0.4.0
author: Sayan N. <ohsayan@outlook.com>
about: This is the TerrabaseDB Database server
args:
- config:
short: c
long: withconfig
value_name: configfile
help: Use a configuration file to start tdb
takes_value: true

@ -93,3 +93,29 @@ fn test_config_file_err() {
let cfg = Config::new(file);
assert!(cfg.is_err());
}
use clap::{load_yaml, App};
/// Get the command line arguments
pub fn get_args() -> Option<String> {
let cfg_layout = load_yaml!("../cli.yml");
let matches = App::from_yaml(cfg_layout).get_matches();
let filename = matches.value_of("config");
filename.map(|fname| fname.to_owned())
}
#[test]
#[cfg(test)]
fn test_args() {
let cmdlineargs = vec!["tdb", "--withconfig", "../examples/config-files/tdb.toml"];
let cfg_layout = load_yaml!("../cli.yml");
let matches = App::from_yaml(cfg_layout).get_matches_from(cmdlineargs);
let filename = matches.value_of("config").unwrap();
assert_eq!("../examples/config-files/tdb.toml", filename);
let cfg = Config::new(std::fs::read_to_string(filename).unwrap()).unwrap();
assert_eq!(
cfg,
Config {
server: ServerConfig { port: 2003 }
}
);
}

Loading…
Cancel
Save