Skip to content

Commit

Permalink
(#12) dtp-server,telemetry-subscribers,clap,colored
Browse files Browse the repository at this point in the history
  • Loading branch information
mario4tier committed Dec 24, 2022
1 parent 67e7232 commit 4a8c2d2
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 49 deletions.
51 changes: 37 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "2"
members = [
"crates/dtp-core",
"crates/dtp-sdk",
"crates/dtp-dev-app",
"crates/dtp-server",
"crates/dtp-test-helper",
]

Expand All @@ -13,6 +13,7 @@ edition = "2021"
homepage = "https://dtp.dev"
license = "Apache-2.0"
documentation = "https://docs.dtp.dev"
default-run = "dtp-server"

[workspace.dependencies]
# By default, DTP is built using the remote git Sui (devnet branch).
Expand All @@ -36,8 +37,15 @@ sui-json-rpc-types = { git = "https://github.com/MystenLabs/sui", branch = "devn
sui-keys = { git = "https://github.com/MystenLabs/sui", branch = "devnet", package = "sui-keys" }
sui-types = { git = "https://github.com/MystenLabs/sui", branch = "devnet", package = "sui-types" }


tokio = { version = "1.22.0", features = ["full"] }
anyhow = "1.0.64"
telemetry-subscribers = { version = "0.2.0" }

anyhow = "1.0.68"
clap = { version = "3.2.22", features = [
"derive",
] } # No upgrade to v4 until color are back.
colored = { version = "2.0.0" }

[workspace.dependencies.serial_test]
# Intended to be used as [dev-dependencies] only.
Expand Down
31 changes: 0 additions & 31 deletions crates/dtp-dev-app/src/main.rs

This file was deleted.

11 changes: 9 additions & 2 deletions crates/dtp-dev-app/Cargo.toml → crates/dtp-server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "dtp-dev-app"
name = "dtp-server"
version.workspace = true
edition.workspace = true
homepage.workspace = true
Expand All @@ -10,8 +10,15 @@ documentation.workspace = true
tokio.workspace = true
anyhow.workspace = true
sui-sdk.workspace = true
clap.workspace = true
colored.workspace = true
telemetry-subscribers.workspace = true

# tracing.workspace = true

# tracing-subscriber = { version = "0.3.16" }

dtp-sdk = { path = "../dtp-sdk/" }

[dev-dependencies]
cargo-husky.workspace = true
cargo-husky.workspace = true
62 changes: 62 additions & 0 deletions crates/dtp-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// DTP Server executable
//
// Typically intended to be deployed as a daemon (Service)
//
use clap::*;
use colored::Colorize;
use std::path::PathBuf;
use telemetry_subscribers;

#[allow(clippy::large_enum_variant)]
#[derive(Parser)]
#[clap(
name = "dtp-server",
about = "Server for Decentralized Transport Protocol over Sui network",
rename_all = "kebab-case",
author,
version
)]
pub enum Command {
#[clap(name = "localnet")]
Localnet {
#[clap(long = "path")]
path: Option<PathBuf>,
},
}

impl Command {
pub async fn execute(self) -> Result<(), anyhow::Error> {
match self {
Command::Localnet { path } => {
if let Some(x) = path {
println!("{}", x.into_os_string().into_string().unwrap());
} else {
println!("Path not provided");
}
Ok(())
}
}
}
}

#[tokio::main]
async fn main() {
#[cfg(windows)]
colored::control::set_virtual_terminal(true).unwrap();

// TODO Socket for external dtp CLI binary (this is the server not the CLI!)
// TODO Look into https://crates.io/crates/sentry-tracing for bail/panic logging.
let _guard = telemetry_subscribers::TelemetryConfig::new("dtp-server")
.with_env()
.init();

let cmd: Command = Command::parse();

match cmd.execute().await {
Ok(_) => (),
Err(err) => {
println!("{}", err.to_string().red());
std::process::exit(1);
}
}
}

0 comments on commit 4a8c2d2

Please sign in to comment.