Skip to content

Commit a704a99

Browse files
authored
Merge pull request #167 from jlebon/pr/edit-nochange
cli/edit: Minor tweaks
2 parents aaa8954 + 9e13cd4 commit a704a99

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/src/cli.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ pub(crate) struct SwitchOpts {
6868
/// Perform an edit operation
6969
#[derive(Debug, Parser)]
7070
pub(crate) struct EditOpts {
71-
/// Path to new system specification; use `-` for stdin
72-
pub(crate) filename: String,
71+
/// Use filename to edit system specification
72+
#[clap(long, short = 'f')]
73+
pub(crate) filename: Option<String>,
7374

7475
/// Don't display progress
7576
#[clap(long)]
@@ -426,19 +427,20 @@ async fn edit(opts: EditOpts) -> Result<()> {
426427
let repo = &sysroot.repo();
427428
let (booted_deployment, _deployments, host) =
428429
crate::status::get_status_require_booted(sysroot)?;
429-
let new_host: Host = if opts.filename == "-" {
430+
let new_host: Host = if let Some(filename) = opts.filename {
431+
let mut r = std::io::BufReader::new(std::fs::File::open(&filename)?);
432+
serde_yaml::from_reader(&mut r)?
433+
} else {
430434
let tmpf = tempfile::NamedTempFile::new()?;
431435
serde_yaml::to_writer(std::io::BufWriter::new(tmpf.as_file()), &host)?;
432436
crate::utils::spawn_editor(&tmpf)?;
433437
tmpf.as_file().seek(std::io::SeekFrom::Start(0))?;
434438
serde_yaml::from_reader(&mut tmpf.as_file())?
435-
} else {
436-
let mut r = std::io::BufReader::new(std::fs::File::open(opts.filename)?);
437-
serde_yaml::from_reader(&mut r)?
438439
};
439440

440441
if new_host.spec == host.spec {
441-
anyhow::bail!("No changes in current host spec");
442+
println!("Edit cancelled, no changes made.");
443+
return Ok(());
442444
}
443445
let new_spec = RequiredHostSpec::from_spec(&new_host.spec)?;
444446
let fetched = pull(repo, new_spec.image, opts.quiet).await?;

0 commit comments

Comments
 (0)