From 9197930e642cdcead416a4cf9ffa64650614ae6c Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 20 Jun 2022 13:17:37 +0200 Subject: Add command to export configuration as JSON Signed-off-by: Matthias Beyer --- Cargo.lock | 1 + tedge/Cargo.toml | 1 + tedge/src/cli.rs | 3 +++ tedge/src/main.rs | 9 +++++++++ 4 files changed, 14 insertions(+) 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, }, + + #[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(()) + } } } -- cgit v1.2.3