implement editing of files

This commit is contained in:
steven-omaha
2022-12-02 17:33:59 +01:00
parent 5ee5aa520c
commit 81c6b04e64
3 changed files with 5 additions and 10 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ fn get_arg_parser() -> Command<'static> {
Command::new(EDIT) Command::new(EDIT)
.about("edit one or more existing group files") .about("edit one or more existing group files")
.arg_required_else_help(true) .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(GROUPS).about("show names of imported groups"))
.subcommand(Command::new(SYNC).about("install packages from all imported groups")) .subcommand(Command::new(SYNC).about("install packages from all imported groups"))
+2 -4
View File
@@ -1,15 +1,14 @@
use std::os::unix::process::CommandExt; use std::os::unix::process::CommandExt;
use std::path::Path; use std::path::PathBuf;
use std::process::Command; use std::process::Command;
use crate::Package; use crate::Package;
pub fn run_edit_command(files: &[&Path]) { pub fn run_edit_command(files: &[PathBuf]) {
let mut cmd = Command::new("nvim"); let mut cmd = Command::new("nvim");
for f in files { for f in files {
cmd.arg(f.to_string_lossy().to_string()); cmd.arg(f.to_string_lossy().to_string());
} }
dbg!(&cmd);
cmd.exec(); cmd.exec();
} }
@@ -19,6 +18,5 @@ pub fn run_install_command(diff: Vec<Package>) {
for p in diff { for p in diff {
cmd.arg(format!("{p}")); cmd.arg(format!("{p}"));
} }
dbg!(&cmd);
cmd.exec(); cmd.exec();
} }
+2 -5
View File
@@ -2,7 +2,7 @@ use std::collections::HashSet;
use std::process::exit; use std::process::exit;
use crate::action; 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::db::{get_all_installed_packages, get_explicitly_installed_packages};
use crate::Group; use crate::Group;
use crate::Package; use crate::Package;
@@ -62,7 +62,6 @@ impl Pacdef {
pub fn run_action_from_arg(self) { pub fn run_action_from_arg(self) {
match self.args.subcommand() { match self.args.subcommand() {
// Some((args::EDIT, groups)) => println!("{groups:#?}"),
Some((action::EDIT, groups)) => self.edit_group_files(groups), Some((action::EDIT, groups)) => self.edit_group_files(groups),
Some((action::GROUPS, _)) => self.show_groups(), Some((action::GROUPS, _)) => self.show_groups(),
Some((action::SYNC, _)) => self.install_packages(), Some((action::SYNC, _)) => self.install_packages(),
@@ -82,9 +81,7 @@ impl Pacdef {
buf buf
}) })
.collect(); .collect();
for f in files { run_edit_command(&files)
println!("{f:#?}");
}
} }
pub(crate) fn show_version(self) { pub(crate) fn show_version(self) {