Przeglądaj źródła

remove cli module & move the cli_config to util

ghassmo 4 lat temu
rodzic
commit
35706c16e1

+ 0 - 1
Cargo.lock

@@ -1392,7 +1392,6 @@ dependencies = [
  "blake2b_simd 1.0.0",
  "bs58",
  "bytes",
- "clap 3.0.7",
  "crypto_api_chachapoly",
  "dirs 4.0.0",
  "futures",

+ 6 - 13
Cargo.toml

@@ -56,7 +56,6 @@ url = {version = "2.2.2", optional = true}
 dirs = {version = "4.0.0", optional = true}
 subtle = {version = "2.4.1", optional = true}
 lazy_static = {version = "1.4.0", optional = true}
-clap = {version = "3.0.7", features = ["derive"], optional = true}
 indexmap = {version = "1.7.0", optional = true}
 itertools = {version = "0.10.3", optional = true}
 
@@ -129,6 +128,8 @@ util = [
     "hex",
     "bincode",
     "serde",
+	"toml",
+    "simplelog",
     "serde_json",
     "dirs",
     "num-bigint",
@@ -157,14 +158,6 @@ system = [
     "async-runtime",
 ]
 
-cli = [
-    "simplelog",
-    "toml",
-    "clap",
-
-    "util",
-]
-
 net = [
     "util",
     "system",
@@ -221,7 +214,7 @@ zkas = [
 [[example]]
 name = "net"
 path = "example/net.rs"
-required-features = ["async-runtime", "cli", "net"]
+required-features = ["async-runtime", "net"]
 
 [[example]]
 name = "tx"
@@ -233,14 +226,14 @@ required-features = ["node"]
 [[example]]
 name = "arithmetic"
 path = "proof/arithmetic.rs"
-required-features = ["cli", "crypto", "zkas"]
+required-features = ["crypto", "zkas"]
 
 [[example]]
 name = "mint"
 path = "proof/mint.rs"
-required-features = ["cli", "crypto", "zkas"]
+required-features = ["crypto", "zkas"]
 
 [[example]]
 name = "burn"
 path = "proof/burn.rs"
-required-features = ["cli", "crypto", "zkas"]
+required-features = ["crypto", "zkas"]

+ 1 - 1
bin/cashierd/Cargo.toml

@@ -5,7 +5,7 @@ edition = "2021"
 
 [dependencies.darkfi]
 path = "../../"
-features = ["node", "rpc", "cli"]
+features = ["node", "rpc"]
 
 [dependencies]
 # Async

+ 11 - 6
bin/cashierd/src/main.rs

@@ -13,10 +13,6 @@ use simplelog::{ColorChoice, TermLogger, TerminalMode};
 
 use darkfi::{
     blockchain::{rocks::columns, Rocks, RocksColumn},
-    cli::{
-        cli_config::{log_config, spawn_config},
-        Config,
-    },
     crypto::{
         address::Address,
         keypair::{PublicKey, SecretKey},
@@ -33,7 +29,13 @@ use darkfi::{
         jsonrpc::{error as jsonerr, response as jsonresp, ErrorCode::*, JsonRequest, JsonResult},
         rpcserver::{listen_and_serve, RequestHandler, RpcServerConfig},
     },
-    util::{expand_path, join_config_path, parse::truncate, serial::serialize, NetworkName},
+    util::{
+        cli::{log_config, spawn_config, Config},
+        expand_path, join_config_path,
+        parse::truncate,
+        serial::serialize,
+        NetworkName,
+    },
     zk::circuit::{MintContract, SpendContract},
     Error, Result,
 };
@@ -745,7 +747,10 @@ async fn main() -> Result<()> {
     // Spawn config file if it's not in place already.
     spawn_config(&config_path, CONFIG_FILE_CONTENTS)?;
 
-    let (lvl, conf) = log_config(matches)?;
+    let verbosity_level = matches.occurrences_of("verbose");
+
+    let (lvl, conf) = log_config(verbosity_level)?;
+
     TermLogger::init(lvl, conf, TerminalMode::Mixed, ColorChoice::Auto)?;
 
     let config: CashierdConfig = Config::<CashierdConfig>::load(config_path)?;

+ 1 - 1
bin/dao-cli/Cargo.toml

@@ -7,7 +7,7 @@ edition = "2021"
 
 [dependencies.darkfi]
 path = "../../"
-features = ["rpc", "cli"]
+features = ["rpc"]
 
 [dependencies]
 # Async

+ 1 - 2
bin/dao-cli/src/main.rs

@@ -7,9 +7,8 @@ use serde_json::{json, Value};
 use url::Url;
 
 use darkfi::{
-    cli::Config,
     rpc::{jsonrpc, jsonrpc::JsonResult},
-    util::async_util,
+    util::{async_util, cli::Config},
     Error, Result,
 };
 

+ 1 - 1
bin/darkfid/Cargo.toml

@@ -5,7 +5,7 @@ edition = "2021"
 
 [dependencies.darkfi]
 path = "../../"
-features = ["node", "rpc", "cli"]
+features = ["node", "rpc"]
 
 [dependencies]
 # Async

+ 8 - 6
bin/darkfid/src/main.rs

@@ -14,10 +14,6 @@ use url::Url;
 
 use darkfi::{
     blockchain::{rocks::columns, Rocks, RocksColumn},
-    cli::{
-        cli_config::{log_config, spawn_config},
-        Config,
-    },
     crypto::{
         address::Address,
         keypair::{Keypair, PublicKey, SecretKey},
@@ -37,7 +33,10 @@ use darkfi::{
         },
         rpcserver::{listen_and_serve, RequestHandler, RpcServerConfig},
     },
-    util::{decode_base10, encode_base10, expand_path, join_config_path, NetworkName},
+    util::{
+        cli::{log_config, spawn_config, Config},
+        decode_base10, encode_base10, expand_path, join_config_path, NetworkName,
+    },
     zk::circuit::{MintContract, SpendContract},
     Error, Result,
 };
@@ -872,7 +871,10 @@ async fn main() -> Result<()> {
     // Spawn config file if it's not in place already.
     spawn_config(&config_path, CONFIG_FILE_CONTENTS)?;
 
-    let (lvl, conf) = log_config(matches)?;
+    let verbosity_level = matches.occurrences_of("verbose");
+
+    let (lvl, conf) = log_config(verbosity_level)?;
+
     TermLogger::init(lvl, conf, TerminalMode::Mixed, ColorChoice::Auto)?;
 
     let config: DarkfidConfig = Config::<DarkfidConfig>::load(config_path)?;

+ 1 - 1
bin/drk/Cargo.toml

@@ -5,7 +5,7 @@ edition = "2021"
 
 [dependencies.darkfi]
 path= "../../"
-features = ["rpc", "cli"]
+features = ["rpc"]
 
 [dependencies]
 # Async

+ 10 - 6
bin/drk/src/main.rs

@@ -9,12 +9,13 @@ use simplelog::{ColorChoice, TermLogger, TerminalMode};
 use url::Url;
 
 use darkfi::{
-    cli::{
-        cli_config::{log_config, spawn_config},
-        Config,
-    },
     rpc::{jsonrpc, jsonrpc::JsonResult},
-    util::{join_config_path, path::expand_path, NetworkName},
+    util::{
+        cli::{log_config, spawn_config, Config},
+        join_config_path,
+        path::expand_path,
+        NetworkName,
+    },
     Error, Result,
 };
 
@@ -474,7 +475,10 @@ async fn main() -> Result<()> {
     // Spawn config file if it's not in place already.
     spawn_config(&config_path, CONFIG_FILE_CONTENTS)?;
 
-    let (lvl, conf) = log_config(matches)?;
+    let verbosity_level = matches.occurrences_of("verbose");
+
+    let (lvl, conf) = log_config(verbosity_level)?;
+
     TermLogger::init(lvl, conf, TerminalMode::Mixed, ColorChoice::Auto)?;
 
     let config = Config::<DrkConfig>::load(config_path)?;

+ 2 - 2
bin/gatewayd/Cargo.toml

@@ -5,7 +5,7 @@ edition = "2021"
 
 [dependencies.darkfi]
 path= "../../"
-features = ["node", "cli"]
+features = ["node"]
 
 [dependencies]
 # Async
@@ -22,4 +22,4 @@ num_cpus = "1.13.1"
 simplelog = "0.11.2"
 
 # Encoding and parsing
-serde = {version = "1.0.133", features = ["derive"]}
+serde = {version = "1.0.133", features = ["derive"]}

+ 8 - 6
bin/gatewayd/src/main.rs

@@ -9,12 +9,11 @@ use simplelog::{ColorChoice, TermLogger, TerminalMode};
 
 use darkfi::{
     blockchain::{rocks::columns, Rocks, RocksColumn},
-    cli::{
-        cli_config::{log_config, spawn_config},
-        Config,
-    },
     node::service::gateway::GatewayService,
-    util::{expand_path, join_config_path},
+    util::{
+        cli::{log_config, spawn_config, Config},
+        expand_path, join_config_path,
+    },
     Result,
 };
 
@@ -76,7 +75,10 @@ async fn main() -> Result<()> {
     // Spawn config file if it's not in place already.
     spawn_config(&config_path, CONFIG_FILE_CONTENTS)?;
 
-    let (lvl, conf) = log_config(matches)?;
+    let verbosity_level = matches.occurrences_of("verbose");
+
+    let (lvl, conf) = log_config(verbosity_level)?;
+
     TermLogger::init(lvl, conf, TerminalMode::Mixed, ColorChoice::Auto)?;
 
     let config: GatewaydConfig = Config::<GatewaydConfig>::load(config_path)?;

+ 1 - 1
bin/ircd/Cargo.toml

@@ -5,7 +5,7 @@ edition = "2021"
 
 [dependencies.darkfi]
 path = "../../"
-features = ["net", "rpc", "cli"]
+features = ["net", "rpc"]
 
 [dependencies]
 # Async

+ 54 - 52
bin/ircd/src/main.rs

@@ -13,13 +13,12 @@ use std::{
 };
 
 use darkfi::{
-    cli::cli_config::log_config,
     net,
     rpc::{
         jsonrpc::{error as jsonerr, response as jsonresp, ErrorCode::*, JsonRequest, JsonResult},
         rpcserver::{listen_and_serve, RequestHandler, RpcServerConfig},
     },
-    util::expand_path,
+    util::{cli::log_config, expand_path},
     Error, Result,
 };
 
@@ -222,56 +221,56 @@ impl JsonRpcInterface {
     // <-- {"jsonrpc": "2.0", "result": {"nodeID": [], "nodeinfo" [], "id": 42}
     async fn get_info(&self, id: Value, _params: Value) -> JsonResult {
         let resp: serde_json::Value = json!({
-                "id": self.rpc_listen_addr,
-                "connections": {
-                    "outgoing": [
-                        {
-                            "id": "127.2.1.1:0000",
-                            "message": [
-                                "addr",
-                                "get_addr",
-                                "info",
-                                "get_info",
-                                "ping",
-                                "pong",
-                            ]
-                        },
-                        {
-                            "id": "121.1.6.7:9000",
-                            "message": [
-                                "addr",
-                                "get_addr",
-                                "info",
-                                "get_info",
-                                "ping",
-                                "pong",
-                            ]
-                        }],
-                    "incoming": [
-                        {
-                            "id": "124.1.1.6:9333",
-                            "message": [
-                                "addr",
-                                "get_addr",
-                                "info",
-                                "get_info",
-                                "ping",
-                                "pong",
-                            ]
-                        },
-                        {
-                            "id": "120.1.0.5:2111",
-                            "message": [
-                                "addr",
-                                "get_addr",
-                                "info",
-                                "get_info",
-                                "ping",
-                                "pong",
-                            ]
-                        }
-                    ],
+            "id": self.rpc_listen_addr,
+            "connections": {
+                "outgoing": [
+                {
+                    "id": "127.2.1.1:0000",
+                    "message": [
+                        "addr",
+                        "get_addr",
+                        "info",
+                        "get_info",
+                        "ping",
+                        "pong",
+                    ]
                 },
+                {
+                    "id": "121.1.6.7:9000",
+                    "message": [
+                        "addr",
+                        "get_addr",
+                        "info",
+                        "get_info",
+                        "ping",
+                        "pong",
+                    ]
+                }],
+                "incoming": [
+                {
+                    "id": "124.1.1.6:9333",
+                    "message": [
+                        "addr",
+                        "get_addr",
+                        "info",
+                        "get_info",
+                        "ping",
+                        "pong",
+                    ]
+                },
+                {
+                    "id": "120.1.0.5:2111",
+                    "message": [
+                        "addr",
+                        "get_addr",
+                        "info",
+                        "get_info",
+                        "ping",
+                        "pong",
+                    ]
+                }
+                ],
+            },
         });
         JsonResult::Resp(jsonresp(resp, id))
     }
@@ -279,7 +278,10 @@ impl JsonRpcInterface {
 
 fn main() -> Result<()> {
     let options = ProgramOptions::load()?;
-    let (lvl, cfg) = log_config(options.app.clone())?;
+
+    let verbosity_level = options.app.occurrences_of("verbose");
+
+    let (lvl, cfg) = log_config(verbosity_level)?;
 
     TermLogger::init(lvl, cfg, TerminalMode::Mixed, ColorChoice::Auto)?;
 

+ 1 - 1
bin/map/Cargo.toml

@@ -5,7 +5,7 @@ edition = "2021"
 
 [dependencies.darkfi]
 path = "../../"
-features = ["rpc", "cli"]
+features = ["rpc"]
 
 [dependencies]
 # Tui

+ 9 - 6
bin/map/src/main.rs

@@ -1,11 +1,11 @@
 use darkfi::{
-    cli::{
-        cli_config::{log_config, spawn_config},
-        Config,
-    },
     error::{Error, Result},
     rpc::{jsonrpc, jsonrpc::JsonResult},
-    util::{async_util, join_config_path},
+    util::{
+        async_util,
+        cli::{log_config, spawn_config, Config},
+        join_config_path,
+    },
 };
 
 use async_std::sync::Arc;
@@ -101,7 +101,10 @@ impl Map {
 #[async_std::main]
 async fn main() -> Result<()> {
     let options = ProgramOptions::load()?;
-    let (lvl, cfg) = log_config(options.app.clone())?;
+
+    let verbosity_level = options.app.occurrences_of("verbose");
+
+    let (lvl, cfg) = log_config(verbosity_level)?;
 
     let file = File::create(&*options.log_path).unwrap();
     WriteLogger::init(lvl, cfg, file)?;

+ 0 - 3
src/cli/mod.rs

@@ -1,3 +0,0 @@
-pub mod cli_config;
-
-pub use cli_config::Config;

+ 1 - 1
src/error.rs

@@ -56,7 +56,7 @@ pub enum Error {
     #[error("Json serialization error: `{0}`")]
     SerdeJsonError(String),
 
-    #[cfg(feature = "cli")]
+    #[cfg(feature = "util")]
     #[error(transparent)]
     TomlDeserializeError(#[from] toml::de::Error),
 

+ 0 - 3
src/lib.rs

@@ -16,9 +16,6 @@ pub mod tx;
 #[cfg(feature = "net")]
 pub mod net;
 
-#[cfg(feature = "cli")]
-pub mod cli;
-
 #[cfg(feature = "blockchain")]
 pub mod blockchain;
 

+ 1 - 5
src/cli/cli_config.rs → src/util/cli.rs

@@ -7,8 +7,6 @@ use std::{
 };
 
 use serde::{de::DeserializeOwned, Serialize};
-
-use clap::ArgMatches;
 use simplelog::ConfigBuilder;
 
 use crate::{Error, Result};
@@ -53,9 +51,7 @@ pub fn spawn_config(path: &Path, contents: &[u8]) -> Result<()> {
     Ok(())
 }
 
-pub fn log_config(matches: ArgMatches) -> Result<(simplelog::LevelFilter, simplelog::Config)> {
-    let mut verbosity_level = 0;
-    verbosity_level += matches.occurrences_of("verbose");
+pub fn log_config(verbosity_level: u64) -> Result<(simplelog::LevelFilter, simplelog::Config)> {
     let log_level = match verbosity_level {
         0 => simplelog::LevelFilter::Info,
         1 => simplelog::LevelFilter::Debug,

+ 1 - 0
src/util/mod.rs

@@ -3,6 +3,7 @@ pub mod async_serial;
 #[cfg(feature = "async-runtime")]
 pub mod async_util;
 
+pub mod cli;
 pub mod endian;
 pub mod net_name;
 pub mod parse;