feat(export): CLI, data structures
This commit is contained in:
@@ -29,7 +29,18 @@ fn get_group_cmd() -> Command {
|
|||||||
.required(true)
|
.required(true)
|
||||||
.help("a previously imported group"),
|
.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")
|
let import = Command::new("import")
|
||||||
.about("import one or more group files")
|
.about("import one or more group files")
|
||||||
@@ -86,7 +97,7 @@ fn get_group_cmd() -> Command {
|
|||||||
.about("manage groups")
|
.about("manage groups")
|
||||||
.visible_alias("g")
|
.visible_alias("g")
|
||||||
.subcommand_required(true)
|
.subcommand_required(true)
|
||||||
.subcommands([edit, import, list, new, remove, show])
|
.subcommands([edit, export, import, list, new, remove, show])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build the `pacdef package` subcommand.
|
/// Build the `pacdef package` subcommand.
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ pub enum Arguments {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum GroupAction {
|
pub enum GroupAction {
|
||||||
Edit(Groups),
|
Edit(Groups),
|
||||||
|
Export(Groups),
|
||||||
Import(Groups),
|
Import(Groups),
|
||||||
List,
|
List,
|
||||||
New(Groups, Edit),
|
New(Groups, Edit),
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ fn parse_group_args(args: &clap::ArgMatches) -> GroupAction {
|
|||||||
|
|
||||||
match args.subcommand() {
|
match args.subcommand() {
|
||||||
Some(("edit", args)) => Edit(get_groups(args)),
|
Some(("edit", args)) => Edit(get_groups(args)),
|
||||||
|
Some(("export", args)) => Export(get_groups(args)),
|
||||||
Some(("import", args)) => Import(get_groups(args)),
|
Some(("import", args)) => Import(get_groups(args)),
|
||||||
Some(("list", _)) => List,
|
Some(("list", _)) => List,
|
||||||
Some(("new", args)) => New(get_groups(args), get_edit(args)),
|
Some(("new", args)) => New(get_groups(args), get_edit(args)),
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ impl Pacdef {
|
|||||||
|
|
||||||
match args {
|
match args {
|
||||||
Edit(args::Groups(groups)) => self.edit_groups(groups),
|
Edit(args::Groups(groups)) => self.edit_groups(groups),
|
||||||
|
Export(args::Groups(groups)) => self.export_groups(groups),
|
||||||
Import(args::Groups(groups)) => self.import_groups(groups),
|
Import(args::Groups(groups)) => self.import_groups(groups),
|
||||||
List => self.show_groups(),
|
List => self.show_groups(),
|
||||||
New(args::Groups(groups), args::Edit(edit)) => self.new_groups(groups, *edit),
|
New(args::Groups(groups), args::Edit(edit)) => self.new_groups(groups, *edit),
|
||||||
@@ -396,13 +397,24 @@ impl Pacdef {
|
|||||||
|
|
||||||
Ok(())
|
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
|
/// # 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>(
|
fn get_group_file_paths_matching_args<'a>(
|
||||||
file_names: &[String],
|
file_names: &[String],
|
||||||
groups: &'a HashSet<Group>,
|
groups: &'a HashSet<Group>,
|
||||||
|
|||||||
@@ -13,13 +13,15 @@ use crate::path::get_relative_path;
|
|||||||
|
|
||||||
use super::{Package, Section};
|
use super::{Package, Section};
|
||||||
|
|
||||||
/// Representation of a group file, composed of a name (file name from which it
|
/// Representation of a group file.
|
||||||
/// was read), the sections in the file, and the absolute path of the original
|
|
||||||
/// file.
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Group {
|
pub struct Group {
|
||||||
|
/// Name of the group (file name from which it was read, relative to the group
|
||||||
|
/// base dir).
|
||||||
pub(crate) name: String,
|
pub(crate) name: String,
|
||||||
|
/// The sections in the file which in turn hold the packages.
|
||||||
pub(crate) sections: HashSet<Section>,
|
pub(crate) sections: HashSet<Section>,
|
||||||
|
/// The absolute path of the original file.
|
||||||
pub(crate) path: PathBuf,
|
pub(crate) path: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user