Skip to content

Commit dab6323

Browse files
committed
add: print config command
1 parent 69ecf4d commit dab6323

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ This will display the available options for running the server:
1818
```
1919
Simple REST server
2020
21-
Usage: cli [OPTIONS]
21+
Usage: cli [OPTIONS] [COMMAND]
22+
23+
Commands:
24+
config Print config
25+
help Print this message or the help of the given subcommand(s)
2226
2327
Options:
24-
-c, --config-file <CONFIG_FILE> Config file [default: config/default.toml]
28+
-c, --config-path <CONFIG_PATH> Config file [default: config/default.toml]
2529
-v, --version Print version
2630
-h, --help Print help
2731
```

cli/src/main.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ mod telemetry;
2626
use crate::options::Options;
2727
use crate::telemetry::init_telemetry;
2828

29-
use clap::Parser;
29+
use clap::{Parser, Subcommand};
3030

3131
use deadpool_diesel::postgres::{Pool, Runtime};
3232
use deadpool_diesel::Manager;
@@ -46,6 +46,8 @@ use tracing::{error, info};
4646
#[derive(Parser, Debug)]
4747
#[command(about, long_about = None)]
4848
struct Args {
49+
#[command(subcommand)]
50+
command: Option<Commands>,
4951
/// Config file
5052
#[arg(short, long, default_value = "config/default.toml")]
5153
config_path: Vec<String>,
@@ -54,6 +56,12 @@ struct Args {
5456
version: bool,
5557
}
5658

59+
#[derive(Subcommand, Clone, Debug)]
60+
enum Commands {
61+
/// Print config
62+
Config,
63+
}
64+
5765
/// Entry point for running the server.
5866
#[tokio::main]
5967
async fn main() {
@@ -62,14 +70,20 @@ async fn main() {
6270
println!(env!("APP_VERSION"));
6371
return;
6472
}
73+
6574
let options = match Options::new(args.config_path) {
6675
Ok(options) => options,
6776
Err(err) => {
68-
error!("Failed to load config: {}", err);
77+
println!("Failed to load config: {}", err);
6978
return;
7079
}
7180
};
7281

82+
if let Some(Commands::Config) = args.command {
83+
println!("{:#?}", options);
84+
return;
85+
}
86+
7387
init_telemetry(
7488
options.service_name.as_str(),
7589
options.exporter_endpoint.as_str(),

0 commit comments

Comments
 (0)