diff --git a/crates/pacdef_core/src/args/cli.rs b/crates/pacdef_core/src/args/cli.rs index 6a8bd3f..c7a3278 100644 --- a/crates/pacdef_core/src/args/cli.rs +++ b/crates/pacdef_core/src/args/cli.rs @@ -29,7 +29,18 @@ fn get_group_cmd() -> Command { .required(true) .help("a previously imported group"), ) - .visible_alias("e"); + .visible_alias("ed"); + + let export = Command::new("export") + .about("export one or more group files") + .arg_required_else_help(true) + .arg( + Arg::new("groups") + .num_args(1..) + .required(true) + .help("the file to export as group"), + ) + .visible_alias("ex"); let import = Command::new("import") .about("import one or more group files") @@ -86,7 +97,7 @@ fn get_group_cmd() -> Command { .about("manage groups") .visible_alias("g") .subcommand_required(true) - .subcommands([edit, import, list, new, remove, show]) + .subcommands([edit, export, import, list, new, remove, show]) } /// Build the `pacdef package` subcommand. diff --git a/crates/pacdef_core/src/args/datastructure.rs b/crates/pacdef_core/src/args/datastructure.rs index 5250f27..e6e0dd1 100644 --- a/crates/pacdef_core/src/args/datastructure.rs +++ b/crates/pacdef_core/src/args/datastructure.rs @@ -8,6 +8,7 @@ pub enum Arguments { #[derive(Debug)] pub enum GroupAction { Edit(Groups), + Export(Groups), Import(Groups), List, New(Groups, Edit), diff --git a/crates/pacdef_core/src/args/parsing.rs b/crates/pacdef_core/src/args/parsing.rs index 5a54f14..35a6694 100644 --- a/crates/pacdef_core/src/args/parsing.rs +++ b/crates/pacdef_core/src/args/parsing.rs @@ -17,6 +17,7 @@ fn parse_group_args(args: &clap::ArgMatches) -> GroupAction { match args.subcommand() { Some(("edit", args)) => Edit(get_groups(args)), + Some(("export", args)) => Export(get_groups(args)), Some(("import", args)) => Import(get_groups(args)), Some(("list", _)) => List, Some(("new", args)) => New(get_groups(args), get_edit(args)), diff --git a/crates/pacdef_core/src/core.rs b/crates/pacdef_core/src/core.rs index ca45fa3..b481719 100644 --- a/crates/pacdef_core/src/core.rs +++ b/crates/pacdef_core/src/core.rs @@ -64,6 +64,7 @@ impl Pacdef { match args { Edit(args::Groups(groups)) => self.edit_groups(groups), + Export(args::Groups(groups)) => self.export_groups(groups), Import(args::Groups(groups)) => self.import_groups(groups), List => self.show_groups(), New(args::Groups(groups), args::Edit(edit)) => self.new_groups(groups, *edit), @@ -396,13 +397,24 @@ impl Pacdef { Ok(()) } + + fn export_groups(&self, groups: &[String]) -> Result<()> { + let groups = get_group_file_paths_matching_args(groups, &self.groups) + .context("resolving group files")?; + + std::fs::rename(from, to) + + todo!() + } } -/// For the provided CLI arguments, get the path to each corresponding group file. +/// For the provided CLI arguments, get the absolute path to each corresponding +/// group file. /// /// # Errors /// -/// This function will return an error if any of the arguments do not match one of group names. +/// This function will return an error if any of the arguments do not match one +/// of group names. fn get_group_file_paths_matching_args<'a>( file_names: &[String], groups: &'a HashSet, diff --git a/crates/pacdef_core/src/grouping/group.rs b/crates/pacdef_core/src/grouping/group.rs index 31cb0d0..8ea0c7b 100644 --- a/crates/pacdef_core/src/grouping/group.rs +++ b/crates/pacdef_core/src/grouping/group.rs @@ -13,13 +13,15 @@ use crate::path::get_relative_path; use super::{Package, Section}; -/// Representation of a group file, composed of a name (file name from which it -/// was read), the sections in the file, and the absolute path of the original -/// file. +/// Representation of a group file. #[derive(Debug)] pub struct Group { + /// Name of the group (file name from which it was read, relative to the group + /// base dir). pub(crate) name: String, + /// The sections in the file which in turn hold the packages. pub(crate) sections: HashSet
, + /// The absolute path of the original file. pub(crate) path: PathBuf, }