@@ -68,8 +68,9 @@ pub(crate) struct SwitchOpts {
68
68
/// Perform an edit operation
69
69
#[ derive( Debug , Parser ) ]
70
70
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 > ,
73
74
74
75
/// Don't display progress
75
76
#[ clap( long) ]
@@ -426,19 +427,20 @@ async fn edit(opts: EditOpts) -> Result<()> {
426
427
let repo = & sysroot. repo ( ) ;
427
428
let ( booted_deployment, _deployments, host) =
428
429
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 {
430
434
let tmpf = tempfile:: NamedTempFile :: new ( ) ?;
431
435
serde_yaml:: to_writer ( std:: io:: BufWriter :: new ( tmpf. as_file ( ) ) , & host) ?;
432
436
crate :: utils:: spawn_editor ( & tmpf) ?;
433
437
tmpf. as_file ( ) . seek ( std:: io:: SeekFrom :: Start ( 0 ) ) ?;
434
438
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) ?
438
439
} ;
439
440
440
441
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 ( ( ) ) ;
442
444
}
443
445
let new_spec = RequiredHostSpec :: from_spec ( & new_host. spec ) ?;
444
446
let fetched = pull ( repo, new_spec. image , opts. quiet ) . await ?;
0 commit comments