Skip to content

Commit

Permalink
Merge the cli args with the conf file args
Browse files Browse the repository at this point in the history
re #217
  • Loading branch information
laduke committed Mar 28, 2023
1 parent 90b86ae commit f430085
Showing 1 changed file with 23 additions and 29 deletions.
52 changes: 23 additions & 29 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,33 +87,19 @@ pub struct StartArgs {

impl Into<Launcher> for StartArgs {
fn into(self) -> Launcher {
if let Some(config) = self.config {
let res = Launcher::new_from_config(config.to_str().unwrap(), self.config_type);
match res {
Ok(mut res) => {
res.network_id = Some(self.network_id.clone());
res
}
Err(e) => {
eprintln!("{}", e);
std::process::exit(1);
}
}
} else {
Launcher {
domain: self.domain,
hosts: self.hosts,
secret: self.secret,
token: self.token,
wildcard: self.wildcard,
chain_cert: self.chain_cert,
tls_cert: self.tls_cert,
tls_key: self.tls_key,
log_level: self.log_level,
network_id: Some(self.network_id),
local_url: self.local_url,
no_configure_network: self.no_configure_network,
}
Launcher {
domain: self.domain,
hosts: self.hosts,
secret: self.secret,
token: self.token,
wildcard: self.wildcard,
chain_cert: self.chain_cert,
tls_cert: self.tls_cert,
tls_key: self.tls_key,
log_level: self.log_level,
network_id: Some(self.network_id),
local_url: self.local_url,
no_configure_network: self.no_configure_network,
}
}
}
Expand Down Expand Up @@ -147,9 +133,17 @@ pub async fn init() -> Result<(), anyhow::Error> {
}

async fn start(args: StartArgs) -> Result<(), anyhow::Error> {
let launcher: Launcher = args.into();
let cli_args: Launcher = args.clone().into();

let merged_args = args.config
.and_then(|path| Launcher::new_from_config(path.to_str()?, args.config_type).ok())
.map(|mut config| {
config.network_id = Some(args.network_id.clone());
config
})
.map_or(cli_args.clone(), |conf| conf.merge(cli_args));

launcher.start().await?;
merged_args.start().await?;
Ok(())
}

Expand Down

0 comments on commit f430085

Please sign in to comment.