feat: update template for cli
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
60b81f10e4
commit
12735aa1c5
@ -1,9 +1,9 @@
|
||||
[workspace]
|
||||
members = ["crates/service"]
|
||||
members = ["crates/%%name%%"]
|
||||
resolver = "2"
|
||||
|
||||
[workspace.dependencies]
|
||||
service = { path = "crates/service" }
|
||||
%%name%% = { path = "crates/%%name%%" }
|
||||
|
||||
anyhow = { version = "1.0.71" }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
@ -11,4 +11,3 @@ tracing = { version = "0.1", features = ["log"] }
|
||||
tracing-subscriber = { version = "0.3.17" }
|
||||
clap = { version = "4.3.4", features = ["derive", "env"] }
|
||||
dotenv = { version = "0.15.0" }
|
||||
axum = { version = "0.6.18" }
|
||||
|
@ -10,4 +10,3 @@ tracing.workspace = true
|
||||
tracing-subscriber.workspace = true
|
||||
clap.workspace = true
|
||||
dotenv.workspace = true
|
||||
axum.workspace = true
|
31
rust-cli/crates/%%name%%/src/main.rs
Normal file
31
rust-cli/crates/%%name%%/src/main.rs
Normal file
@ -0,0 +1,31 @@
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about, long_about = None, subcommand_required = true)]
|
||||
struct Command {
|
||||
#[command(subcommand)]
|
||||
command: Option<Commands>,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
Init
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
dotenv::dotenv().ok();
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let cli = Command::parse();
|
||||
|
||||
match cli.command.unwrap() {
|
||||
Commands::Init => {
|
||||
tracing::info!("hello %%name%%");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use axum::routing::get;
|
||||
use axum::Router;
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about, long_about = None, subcommand_required = true)]
|
||||
struct Command {
|
||||
#[command(subcommand)]
|
||||
command: Option<Commands>,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
Serve {
|
||||
#[arg(env = "SERVICE_HOST", long, default_value = "127.0.0.1:3000")]
|
||||
host: SocketAddr,
|
||||
},
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
dotenv::dotenv().ok();
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let cli = Command::parse();
|
||||
|
||||
match cli.command {
|
||||
Some(Commands::Serve { host }) => {
|
||||
tracing::info!("Starting service");
|
||||
|
||||
let app = Router::new().route("/", get(root));
|
||||
|
||||
tracing::info!("listening on {}", host);
|
||||
axum::Server::bind(&host)
|
||||
.serve(app.into_make_service())
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn root() -> &'static str {
|
||||
"Hello, Service!"
|
||||
}
|
Loading…
Reference in New Issue
Block a user