From 0f166638e9297e941a5d048b1bccafabf82fab54 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Wed, 1 Nov 2023 09:16:47 -0400 Subject: [PATCH 1/2] cli/edit: Don't error out if host spec unchanged This matches e.g. `kubectl edit`. Signed-off-by: Jonathan Lebon --- lib/src/cli.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/cli.rs b/lib/src/cli.rs index 44f688b5..fec7b877 100644 --- a/lib/src/cli.rs +++ b/lib/src/cli.rs @@ -438,7 +438,8 @@ async fn edit(opts: EditOpts) -> Result<()> { }; if new_host.spec == host.spec { - anyhow::bail!("No changes in current host spec"); + println!("Edit cancelled, no changes made."); + return Ok(()); } let new_spec = RequiredHostSpec::from_spec(&new_host.spec)?; let fetched = pull(repo, &new_spec.image, opts.quiet).await?; From 9e13cd4be2767fc7d7f0d1a933e42a5ed9e52bc3 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Wed, 1 Nov 2023 09:21:56 -0400 Subject: [PATCH 2/2] cli/edit: Default to interactive edit This better matches `kubectl edit`. Signed-off-by: Jonathan Lebon --- lib/src/cli.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/src/cli.rs b/lib/src/cli.rs index fec7b877..6e6c0e00 100644 --- a/lib/src/cli.rs +++ b/lib/src/cli.rs @@ -68,8 +68,9 @@ pub(crate) struct SwitchOpts { /// Perform an edit operation #[derive(Debug, Parser)] pub(crate) struct EditOpts { - /// Path to new system specification; use `-` for stdin - pub(crate) filename: String, + /// Use filename to edit system specification + #[clap(long, short = 'f')] + pub(crate) filename: Option, /// Don't display progress #[clap(long)] @@ -426,15 +427,15 @@ async fn edit(opts: EditOpts) -> Result<()> { let repo = &sysroot.repo(); let (booted_deployment, _deployments, host) = crate::status::get_status_require_booted(sysroot)?; - let new_host: Host = if opts.filename == "-" { + let new_host: Host = if let Some(filename) = opts.filename { + let mut r = std::io::BufReader::new(std::fs::File::open(&filename)?); + serde_yaml::from_reader(&mut r)? + } else { let tmpf = tempfile::NamedTempFile::new()?; serde_yaml::to_writer(std::io::BufWriter::new(tmpf.as_file()), &host)?; crate::utils::spawn_editor(&tmpf)?; tmpf.as_file().seek(std::io::SeekFrom::Start(0))?; serde_yaml::from_reader(&mut tmpf.as_file())? - } else { - let mut r = std::io::BufReader::new(std::fs::File::open(opts.filename)?); - serde_yaml::from_reader(&mut r)? }; if new_host.spec == host.spec {