-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsubcommands_example.rs
57 lines (47 loc) · 1.29 KB
/
subcommands_example.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use conf::{Conf, Subcommands};
use http::Uri as Url;
use std::net::SocketAddr;
use std::path::PathBuf;
/// Configuration for an http client
#[derive(Conf, Debug)]
pub struct HttpClientConfig {
/// Base URL
#[conf(long, env)]
pub url: Url,
/// Number of retries
#[conf(long, env)]
pub retries: u32,
}
/// Configuration for model service
#[derive(Conf, Debug)]
#[conf(name = "subcommands_example")]
pub struct ModelServiceConfig {
/// Listen address to bind to
#[conf(long, env, default_value = "127.0.0.1:9090")]
pub listen_addr: SocketAddr,
/// Auth service:
#[conf(flatten, prefix, help_prefix)]
pub auth: Option<HttpClientConfig>,
/// Database:
#[conf(flatten, prefix, help_prefix)]
pub db: HttpClientConfig,
/// Optional subcommands
#[conf(subcommands)]
pub command: Option<Command>,
}
/// Subcommands that can be used with this service
#[derive(Subcommands, Debug)]
pub enum Command {
RunMigrations(MigrationConfig),
ShowPendingMigrations(MigrationConfig),
}
#[derive(Conf, Debug)]
pub struct MigrationConfig {
/// Path to migrations file (instead of embedded migrations)
#[conf(long, env)]
pub migrations: Option<PathBuf>,
}
fn main() {
let config = ModelServiceConfig::parse();
println!("{config:#?}");
}