Skip to content

Commit eaaf419

Browse files
sd109Scott Davidsonmarkgoddard
authored
Add basic CLI (#28)
* Add basic CLI * Use u16 for port Co-authored-by: Mark Goddard <mark@stackhpc.com> * Use default_value_t for non-string args * Fix: alphabetical * Add CLI help strings --------- Co-authored-by: Scott Davidson <scott@stackhpc.com> Co-authored-by: Mark Goddard <mark@stackhpc.com>
1 parent 8515a07 commit eaaf419

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ aws-smithy-http = "0.54"
1515
aws-smithy-types = "0.54"
1616
aws-types = "0.54"
1717
axum = { version = "0.6", features = ["headers"] }
18+
clap = { version = "4.2.1", features = ["derive", "env"] }
1819
http = "*"
1920
hyper = { version = "0.14", features = ["full"] }
2021
maligned = "0.2.1"

src/main.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
//! * [ndarray] provides [NumPy](https://numpy.orgq)-like n-dimensional arrays used in numerical
2323
//! computation.
2424
25+
use clap::Parser;
2526
use tokio::signal;
2627
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
2728

@@ -34,15 +35,28 @@ mod operations;
3435
mod s3_client;
3536
mod validated_json;
3637

38+
/// S3 Active Storage Proxy command line interface
39+
#[derive(Debug, Parser)]
40+
struct CommandLineArgs {
41+
/// The IP address on which the proxy should listen
42+
#[arg(long, default_value = "0.0.0.0", env = "S3_ACTIVE_STORAGE_HOST")]
43+
host: String,
44+
/// The port to which the proxy should bind
45+
#[arg(long, default_value_t = 8080, env = "S3_ACTIVE_STORAGE_PORT")]
46+
port: u16,
47+
}
48+
3749
/// Application entry point
3850
#[tokio::main]
3951
async fn main() {
52+
let args = CommandLineArgs::parse();
53+
4054
init_tracing();
4155

4256
let router = app::router();
4357

44-
// run it with hyper on localhost:8080
45-
axum::Server::bind(&"0.0.0.0:8080".parse().unwrap())
58+
// run it with hyper
59+
axum::Server::bind(&format!("{}:{}", args.host, args.port).parse().unwrap())
4660
.serve(router.into_make_service())
4761
.with_graceful_shutdown(shutdown_signal())
4862
.await

0 commit comments

Comments
 (0)