mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 01:24:26 +01:00
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:
committed by
Rusty Russell
parent
c36cef08bc
commit
b359a24772
@@ -6,7 +6,7 @@ use cln_plugin::{options, Builder, Error, Plugin};
|
||||
use tokio;
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), anyhow::Error> {
|
||||
let plugin = Builder::new((), tokio::io::stdin(), tokio::io::stdout())
|
||||
if let Some(plugin) = Builder::new((), tokio::io::stdin(), tokio::io::stdout())
|
||||
.option(options::ConfigOption::new(
|
||||
"test-option",
|
||||
options::Value::Integer(42),
|
||||
@@ -16,8 +16,12 @@ async fn main() -> Result<(), anyhow::Error> {
|
||||
.subscribe("connect", connect_handler)
|
||||
.hook("peer_connected", peer_connected_handler)
|
||||
.start()
|
||||
.await?;
|
||||
plugin.join().await
|
||||
.await?
|
||||
{
|
||||
plugin.join().await
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
async fn testmethod(_p: Plugin<()>, _v: serde_json::Value) -> Result<serde_json::Value, Error> {
|
||||
@@ -29,7 +33,10 @@ async fn connect_handler(_p: Plugin<()>, v: serde_json::Value) -> Result<(), Err
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn peer_connected_handler(_p: Plugin<()>, v: serde_json::Value) -> Result<serde_json::Value, Error> {
|
||||
async fn peer_connected_handler(
|
||||
_p: Plugin<()>,
|
||||
v: serde_json::Value,
|
||||
) -> Result<serde_json::Value, Error> {
|
||||
log::info!("Got a connect hook call: {}", v);
|
||||
Ok(json!({"result": "continue"}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user