From 3502e0a70b549845f56c5d857df88aafb8930721 Mon Sep 17 00:00:00 2001 From: steven-omaha <35634100+steven-omaha@users.noreply.github.com> Date: Thu, 12 Jan 2023 11:32:35 +0100 Subject: [PATCH] add 'new --edit' --- src/args.rs | 7 +++++++ src/core.rs | 14 +++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/args.rs b/src/args.rs index 0ef2403..4a0e6a4 100644 --- a/src/args.rs +++ b/src/args.rs @@ -29,6 +29,13 @@ fn get_arg_parser() -> Command<'static> { Command::new(NEW) .about("create new group files") .arg_required_else_help(true) + .arg( + Arg::new("edit") + .short('e') + .long("edit") + .help("edit the new group files after creation") + .action(clap::ArgAction::SetTrue), + ) .arg(Arg::new("groups").multiple_values(true)), ) .subcommand( diff --git a/src/core.rs b/src/core.rs index c4a357c..90855fd 100644 --- a/src/core.rs +++ b/src/core.rs @@ -215,17 +215,25 @@ impl Pacdef { Ok(()) } - fn new_groups(&self, files: &ArgMatches) -> Result<()> { - let paths = get_assumed_group_file_names(files)?; + fn new_groups(&self, arg: &ArgMatches) -> Result<()> { + let paths = get_assumed_group_file_names(arg)?; for file in &paths { ensure!(!file.exists(), "group already exists under {file:?}"); } - for file in paths { + for file in &paths { File::create(file)?; } + if arg.get_flag("edit") { + let success = run_edit_command(&paths) + .context("running editor")? + .success(); + + ensure!(success, "editor exited with error"); + } + Ok(()) } }