summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@ifm.com>2022-06-20 13:17:37 +0200
committerMatthias Beyer <matthias.beyer@ifm.com>2022-06-20 13:17:56 +0200
commit9197930e642cdcead416a4cf9ffa64650614ae6c (patch)
treea1eadef6b3ffa812238596817c825a4e3cb79b2e
parent6b22b9a29e37a4319395adc029b50a3dd2f5a8b3 (diff)
Add command to export configuration as JSONfeature/add_tedge_api/config-json-export
Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
-rw-r--r--Cargo.lock1
-rw-r--r--tedge/Cargo.toml1
-rw-r--r--tedge/src/cli.rs3
-rw-r--r--tedge/src/main.rs9
4 files changed, 14 insertions, 0 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 1f24035b..54444664 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3385,6 +3385,7 @@ dependencies = [
"plugin_notification",
"plugin_sysstat",
"pretty",
+ "serde_json",
"tedge_api",
"tedge_core",
"tedge_lib",
diff --git a/tedge/Cargo.toml b/tedge/Cargo.toml
index 533526af..464f1d2d 100644
--- a/tedge/Cargo.toml
+++ b/tedge/Cargo.toml
@@ -23,6 +23,7 @@ termimad = "0.20.1"
term_size = "0.3.2"
owo-colors = "3.4.0"
textwrap = "0.15.0"
+serde_json = "1"
tedge_api = { path = "../crates/core/tedge_api" }
tedge_core = { path = "../crates/core/tedge_core" }
diff --git a/tedge/src/cli.rs b/tedge/src/cli.rs
index 821b1cd9..79f47231 100644
--- a/tedge/src/cli.rs
+++ b/tedge/src/cli.rs
@@ -63,4 +63,7 @@ pub(crate) enum CliCommand {
/// Print the doc only for this plugin
plugin_name: Option<String>,
},
+
+ #[clap(name = "export-config")]
+ ExportConfig { config: PathBuf },
}
diff --git a/tedge/src/main.rs b/tedge/src/main.rs
index 6800c45a..73ce9fbc 100644
--- a/tedge/src/main.rs
+++ b/tedge/src/main.rs
@@ -210,6 +210,15 @@ async fn main() -> miette::Result<()> {
Ok(())
}
+
+ cli::CliCommand::ExportConfig { config } => {
+ let (_cancel_sender, application) =
+ registry.app_builder.with_config_from_path(config).await?;
+
+ let out = std::io::stdout();
+ serde_json::to_writer(out.lock(), application.config()).into_diagnostic()?;
+ Ok(())
+ }
}
}