Skip to content

Commit 89bad2d

Browse files
committed
Read CLI options from environment if not present
Allow configuration to be set more easily when deployed in a container
1 parent 8b6af5f commit 89bad2d

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async-graphql = { version = "=7.0.9", features = ["tracing"] }
1212
async-graphql-axum = "=7.0.9"
1313
axum = "0.7.5"
1414
chrono = "0.4.38"
15-
clap = { version = "4.5.16", features = ["cargo", "derive"] }
15+
clap = { version = "4.5.16", features = ["cargo", "derive", "env"] }
1616
clap-verbosity-flag = "2.2.1"
1717
futures = "0.3.30"
1818
opentelemetry = "0.24.0"

src/cli.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use url::Url;
2222

2323
#[derive(Debug, Parser)]
2424
pub struct Cli {
25-
#[clap(short, long, default_value = "numtracker.db")]
25+
#[clap(short, long, default_value = "numtracker.db", env = "NUMTRACKER_DB")]
2626
pub(crate) db: PathBuf,
2727
#[clap(flatten, next_help_heading = "Logging/Debug")]
2828
verbose: Verbosity<InfoLevel>,
@@ -35,10 +35,10 @@ pub struct Cli {
3535
#[derive(Debug, Parser)]
3636
pub struct TracingOptions {
3737
/// The URL of the tracing OTLP platform (eg Jaeger)
38-
#[clap(long = "tracing")]
38+
#[clap(long = "tracing", env = "NUMTRACKER_TRACING")]
3939
tracing_url: Option<Url>,
4040
/// The minimum level of tracing events to send
41-
#[clap(long, default_value_t = Level::INFO)]
41+
#[clap(long, default_value_t = Level::INFO, env = "NUMTRACKER_TRACING_LEVEL")]
4242
tracing_level: Level,
4343
}
4444

@@ -53,10 +53,10 @@ pub enum Command {
5353
#[derive(Debug, Parser)]
5454
pub struct ServeOptions {
5555
/// The IP for this to service to be bound to
56-
#[clap(short = 'H', long, default_value_t = Ipv4Addr::UNSPECIFIED)]
56+
#[clap(short = 'H', long, default_value_t = Ipv4Addr::UNSPECIFIED, env="NUMTRACKER_HOST")]
5757
host: Ipv4Addr,
5858
/// The port to open for requests
59-
#[clap(short, long, default_value_t = 8000)]
59+
#[clap(short, long, default_value_t = 8000, env = "NUMTRACKER_PORT")]
6060
port: u16,
6161
}
6262

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ mod template;
2929
async fn main() -> Result<(), Box<dyn Error>> {
3030
let args = Cli::init();
3131
let _ = logging::init(args.log_level(), args.tracing());
32-
debug!(args = format_args!("{:#?}", args));
32+
debug!(?args, "Starting numtracker service");
3333
match args.command {
3434
Command::Serve(opts) => graphql::serve_graphql(&args.db, opts).await,
3535
Command::Schema => graphql::graphql_schema(),

0 commit comments

Comments
 (0)