diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-07-12 13:21:10 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-07-12 13:21:10 +0300 |
commit | 7fa564f500af542771bda7bfada85366a2f47f35 (patch) | |
tree | 034c33f574ea0fd707ac3c5784ba82fb4ead0113 /src | |
parent | 7d1836c4f9685bc67aeaf41ab6a7d2f43008288b (diff) | |
download | vmadm-7fa564f500af542771bda7bfada85366a2f47f35.tar.gz |
feat: add sub-command "config"
Sponsored-by: author
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/vmadm.rs | 10 | ||||
-rw-r--r-- | src/cmd/config.rs | 14 | ||||
-rw-r--r-- | src/cmd/mod.rs | 3 | ||||
-rw-r--r-- | src/config.rs | 4 |
4 files changed, 29 insertions, 2 deletions
diff --git a/src/bin/vmadm.rs b/src/bin/vmadm.rs index 711bc98..897b145 100644 --- a/src/bin/vmadm.rs +++ b/src/bin/vmadm.rs @@ -27,6 +27,11 @@ enum Command { spec: PathBuf, }, + Config { + #[structopt(flatten)] + common: CommonOptions, + }, + List { #[structopt(flatten)] common: CommonOptions, @@ -85,6 +90,11 @@ fn main() -> anyhow::Result<()> { cmd::new(&specs)?; } + Command::Config { common } => { + let config = config(&common)?; + cmd::config(&config)?; + } + Command::List { common } => { let config = config(&common)?; cmd::list(&config)?; diff --git a/src/cmd/config.rs b/src/cmd/config.rs new file mode 100644 index 0000000..996439b --- /dev/null +++ b/src/cmd/config.rs @@ -0,0 +1,14 @@ +//! The `config` sub-command. + +use std::io::Write; + +use crate::config::Configuration; + +/// The `config` sub-command. +/// +/// Write the actual run-time configuration to stdout. +pub fn config(config: &Configuration) -> Result<(), std::io::Error> { + let config = serde_yaml::to_vec(&config).unwrap(); + std::io::stdout().write_all(&config)?; + Ok(()) +} diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 8ae8f70..490cdc4 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -20,3 +20,6 @@ pub use shutdown::shutdown; pub mod cloud_init; pub use cloud_init::cloud_init; + +pub mod config; +pub use config::config; diff --git a/src/config.rs b/src/config.rs index 3f1b341..0ff251a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,13 +2,13 @@ use crate::util::{expand_optional_pathbuf, expand_optional_pathbufs}; use log::debug; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; use std::default::Default; use std::fs; use std::path::{Path, PathBuf}; /// Configuration from configuration file. -#[derive(Default, Debug, Deserialize)] +#[derive(Default, Debug, Deserialize, Serialize)] pub struct Configuration { /// Base image, if provided. pub default_base_image: Option<PathBuf>, |