Skip to content

Commit 9e13cd4

Browse files
committed
cli/edit: Default to interactive edit
This better matches `kubectl edit`. Signed-off-by: Jonathan Lebon <[email protected]>
1 parent 0f16663 commit 9e13cd4

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/src/cli.rs

Lines changed: 7 additions & 6 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,15 +427,15 @@ 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 {

0 commit comments

Comments
 (0)