cln-plugin: Handle --help invocations better

We now have ternary outcomes for `Builder.configure()` and
`Builder.start()`:

 - Ok(Some(p)) means we were configured correctly, and can continue
   with our work normally
 - Ok(None) means that `lightningd` was invoked with `--help`, we
   weren't configured (which is not an error since the `lightningd` just
   implicitly told us to shut down) and user code should clean up and
   exit as well
 - Err(e) something went wrong, user code may report an error and exit.
This commit is contained in:
Christian Decker
2022-04-10 16:56:13 +02:00
committed by Rusty Russell
parent c36cef08bc
commit b359a24772
3 changed files with 41 additions and 13 deletions

View File

@@ -28,19 +28,25 @@ async fn main() -> Result<()> {
ca_cert,
};
let plugin = Builder::new(state.clone(), tokio::io::stdin(), tokio::io::stdout())
let plugin = match Builder::new(state.clone(), tokio::io::stdin(), tokio::io::stdout())
.option(options::ConfigOption::new(
"grpc-port",
options::Value::Integer(-1),
"Which port should the grpc plugin listen for incoming connections?",
))
.configure()
.await?;
.await?
{
Some(p) => p,
None => return Ok(()),
};
let bind_port = match plugin.option("grpc-port") {
Some(options::Value::Integer(-1)) => {
log::info!("`grpc-port` option is not configured, exiting.");
plugin.disable("`grpc-port` option is not configured.").await?;
plugin
.disable("`grpc-port` option is not configured.")
.await?;
return Ok(());
}
Some(options::Value::Integer(i)) => i,