From 533bc712238ea7d0030ff738be7e22df9050aea1 Mon Sep 17 00:00:00 2001 From: "Dr. Matthias Ratajczak" Date: Fri, 2 Dec 2022 17:33:59 +0100 Subject: [PATCH] implement editing of files --- src/args.rs | 2 +- src/cmd.rs | 6 ++---- src/core.rs | 7 ++----- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/args.rs b/src/args.rs index 48c7310..c38c151 100644 --- a/src/args.rs +++ b/src/args.rs @@ -12,7 +12,7 @@ fn get_arg_parser() -> Command<'static> { Command::new(EDIT) .about("edit one or more existing group files") .arg_required_else_help(true) - .arg(Arg::new("group")), + .arg(Arg::new("group").multiple_values(true)), ) .subcommand(Command::new(GROUPS).about("show names of imported groups")) .subcommand(Command::new(SYNC).about("install packages from all imported groups")) diff --git a/src/cmd.rs b/src/cmd.rs index 910c3fc..d1cb5c1 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -1,15 +1,14 @@ use std::os::unix::process::CommandExt; -use std::path::Path; +use std::path::PathBuf; use std::process::Command; use crate::Package; -pub fn run_edit_command(files: &[&Path]) { +pub fn run_edit_command(files: &[PathBuf]) { let mut cmd = Command::new("nvim"); for f in files { cmd.arg(f.to_string_lossy().to_string()); } - dbg!(&cmd); cmd.exec(); } @@ -19,6 +18,5 @@ pub fn run_install_command(diff: Vec) { for p in diff { cmd.arg(format!("{p}")); } - dbg!(&cmd); cmd.exec(); } diff --git a/src/core.rs b/src/core.rs index f7624ce..e522e3f 100644 --- a/src/core.rs +++ b/src/core.rs @@ -2,7 +2,7 @@ use std::collections::HashSet; use std::process::exit; use crate::action; -use crate::cmd::run_install_command; +use crate::cmd::{run_edit_command, run_install_command}; use crate::db::{get_all_installed_packages, get_explicitly_installed_packages}; use crate::Group; use crate::Package; @@ -62,7 +62,6 @@ impl Pacdef { pub fn run_action_from_arg(self) { match self.args.subcommand() { - // Some((args::EDIT, groups)) => println!("{groups:#?}"), Some((action::EDIT, groups)) => self.edit_group_files(groups), Some((action::GROUPS, _)) => self.show_groups(), Some((action::SYNC, _)) => self.install_packages(), @@ -82,9 +81,7 @@ impl Pacdef { buf }) .collect(); - for f in files { - println!("{f:#?}"); - } + run_edit_command(&files) } pub(crate) fn show_version(self) {