diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-07-12 13:31:17 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-07-12 13:31:17 +0300 |
commit | 15c375a0400fcb6de37dde14458b9b2566ae61de (patch) | |
tree | d1e48c467537d324f00ceb77e90cac5301149f36 /src | |
parent | 7fa564f500af542771bda7bfada85366a2f47f35 (diff) | |
download | vmadm-15c375a0400fcb6de37dde14458b9b2566ae61de.tar.gz |
feat: subcommand 'spec'
Sponsored-by: author
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/vmadm.rs | 13 | ||||
-rw-r--r-- | src/cmd/mod.rs | 3 | ||||
-rw-r--r-- | src/cmd/spec.rs | 16 | ||||
-rw-r--r-- | src/spec.rs | 2 |
4 files changed, 33 insertions, 1 deletions
diff --git a/src/bin/vmadm.rs b/src/bin/vmadm.rs index 897b145..7a4493e 100644 --- a/src/bin/vmadm.rs +++ b/src/bin/vmadm.rs @@ -32,6 +32,14 @@ enum Command { common: CommonOptions, }, + Spec { + #[structopt(flatten)] + common: CommonOptions, + + #[structopt(parse(from_os_str))] + spec: PathBuf, + }, + List { #[structopt(flatten)] common: CommonOptions, @@ -95,6 +103,11 @@ fn main() -> anyhow::Result<()> { cmd::config(&config)?; } + Command::Spec { common, spec } => { + let specs = get_specs(&common, &spec)?; + cmd::spec(&specs)?; + } + Command::List { common } => { let config = config(&common)?; cmd::list(&config)?; diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 490cdc4..85ccf4e 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -23,3 +23,6 @@ pub use cloud_init::cloud_init; pub mod config; pub use config::config; + +pub mod spec; +pub use spec::spec; diff --git a/src/cmd/spec.rs b/src/cmd/spec.rs new file mode 100644 index 0000000..b41f234 --- /dev/null +++ b/src/cmd/spec.rs @@ -0,0 +1,16 @@ +//! The `spec` sub-command. + +use std::io::Write; + +use crate::spec::Specification; + +/// The `spec` sub-command. +/// +/// Write the actual VM specifications to stdout. +pub fn spec(specs: &[Specification]) -> Result<(), std::io::Error> { + for spec in specs { + let spec = serde_yaml::to_vec(&spec).unwrap(); + std::io::stdout().write_all(&spec)?; + } + Ok(()) +} diff --git a/src/spec.rs b/src/spec.rs index a00a5e8..e98377c 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -133,7 +133,7 @@ where /// /// This is the specification as read from the input file, with the /// defaults from the configuration file already applied. -#[derive(Debug)] +#[derive(Debug, Serialize)] pub struct Specification { /// Name of new virtual machine to create. pub name: String, |