-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#12) dtp-server,telemetry-subscribers,clap,colored
- Loading branch information
1 parent
67e7232
commit 4a8c2d2
Showing
5 changed files
with
118 additions
and
49 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |