From e7e83f3c1ec19e7bdedd0e85eb6d7688fc8ee34b Mon Sep 17 00:00:00 2001
From: Eduardo Trujillo <ed@chromabits.com>
Date: Tue, 15 Nov 2022 13:31:26 -0800
Subject: [PATCH] refactor(cli): Make console-subscriber dependency optional

---
 Cargo.toml       | 9 ++++++---
 README.md        | 8 ++++++++
 src/cli/serve.rs | 2 --
 src/main.rs      | 3 +++
 4 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index ebaa783..45b80b6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -42,7 +42,7 @@ handlebars = "3.4"
 regex = "1.3"
 tokio-stream = "0.1"
 clap = { version = "3.1", features = ["derive"]}
-console-subscriber = "0.1.8"
+console-subscriber = { version = "0.1.8", optional = true }
 
 [dependencies.collective]
 git = "https://gitlab.chromabits.com/etcinit/collective.git"
@@ -50,7 +50,7 @@ rev = "f6f46f690d63f142ad6c5e95dd806d24b9cea6d4"
 
 [dependencies.tokio]
 version = "1.0"
-features = ["signal", "macros", "fs", "sync", "tracing"]
+features = ["signal", "macros", "fs", "sync"]
 
 [dependencies.tokio-util]
 version = "0.7"
@@ -62,4 +62,7 @@ rev = "1bd30fbd1a219e8982571da48eb68f34317d1e15"
 
 [dependencies.async-compression]
 version = "0.3"
-features = ["gzip", "tokio"]
\ No newline at end of file
+features = ["gzip", "tokio"]
+
+[features]
+console-subscriber = ["dep:console-subscriber", "tokio/tracing"]
\ No newline at end of file
diff --git a/README.md b/README.md
index de28913..24574e2 100644
--- a/README.md
+++ b/README.md
@@ -71,3 +71,11 @@ minikube service --url espresso
 `RUST_LOG=info cargo run` to build and run the server.
 
 `RUST_LOG=info cargo test` to run all tests.
+
+**tokio-console:**
+
+Support for `tokio-console` can be enabled with the `console-subscriber` flag:
+
+```sh
+RUSTFLAGS="--cfg tokio_unstable" cargo run -F console-subscriber
+```
\ No newline at end of file
diff --git a/src/cli/serve.rs b/src/cli/serve.rs
index 0bd1181..641dc51 100644
--- a/src/cli/serve.rs
+++ b/src/cli/serve.rs
@@ -35,8 +35,6 @@ type Result<T, E = Error> = std::result::Result<T, E>;
 pub async fn serve(config: Arc<Config>) -> Result<()> {
   MONITOR.init().context(MonitorError)?;
 
-  console_subscriber::init();
-
   // Set up a channel for receiving thread notifications.
   let (monitor_tx, monitor_rx) = mpsc::channel();
 
diff --git a/src/main.rs b/src/main.rs
index bdcf935..3ed7398 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -28,6 +28,9 @@ type Result<T, E = Error> = std::result::Result<T, E>;
 
 #[actix_rt::main]
 async fn main() -> Result<()> {
+  #[cfg(feature = "console-subscriber")]
+  console_subscriber::init();
+
   let result = inner_main().await;
 
   if let Err(Error::CliError {
-- 
GitLab