Skip to content

Commit

Permalink
rename managed to required
Browse files Browse the repository at this point in the history
  • Loading branch information
ripytide committed Dec 23, 2024
1 parent e1483fd commit e469a27
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 55 deletions.
4 changes: 2 additions & 2 deletions src/backends/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ macro_rules! options {
is_empty!($(($upper_backend, $lower_backend)),*);
to_package_ids!($(($upper_backend, $lower_backend)),*);

pub fn map_managed_packages(mut self, config: &Config) -> Result<Self> {
pub fn map_required(mut self, config: &Config) -> Result<Self> {
$(
if is_enabled(AnyBackend::$upper_backend, config) {
self.$lower_backend = $upper_backend::map_managed_packages(self.$lower_backend, config)?;
self.$lower_backend = $upper_backend::map_required(self.$lower_backend, config)?;
}
)*

Expand Down
6 changes: 3 additions & 3 deletions src/backends/apt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct AptOptions {}
impl Backend for Apt {
type Options = AptOptions;

fn map_managed_packages(
fn map_required(
packages: BTreeMap<String, Self::Options>,
_: &Config,
) -> Result<BTreeMap<String, Self::Options>> {
Expand Down Expand Up @@ -84,12 +84,12 @@ impl Backend for Apt {
}

fn missing(
managed: Self::Options,
required: Self::Options,
installed: Option<Self::Options>,
) -> Option<Self::Options> {
match installed {
Some(_) => None,
None => Some(managed),
None => Some(required),
}
}
}
6 changes: 3 additions & 3 deletions src/backends/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct ArchOptions {}
impl Backend for Arch {
type Options = ArchOptions;

fn map_managed_packages(
fn map_required(
mut packages: BTreeMap<String, Self::Options>,
config: &Config,
) -> Result<BTreeMap<String, Self::Options>> {
Expand Down Expand Up @@ -235,10 +235,10 @@ impl Backend for Arch {
)
}

fn missing(managed: Self::Options, installed: Option<Self::Options>) -> Option<Self::Options> {
fn missing(required: Self::Options, installed: Option<Self::Options>) -> Option<Self::Options> {
match installed {
Some(_) => None,
None => Some(managed),
None => Some(required),
}
}
}
6 changes: 3 additions & 3 deletions src/backends/brew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct BrewOptions {}
impl Backend for Brew {
type Options = BrewOptions;

fn map_managed_packages(
fn map_required(
packages: BTreeMap<String, Self::Options>,
_: &Config,
) -> Result<BTreeMap<String, Self::Options>> {
Expand Down Expand Up @@ -80,12 +80,12 @@ impl Backend for Brew {
}

fn missing(
managed: Self::Options,
required: Self::Options,
installed: Option<Self::Options>,
) -> Option<Self::Options> {
match installed {
Some(_) => None,
None => Some(managed),
None => Some(required),
}
}
}
6 changes: 3 additions & 3 deletions src/backends/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct CargoOptions {
impl Backend for Cargo {
type Options = CargoOptions;

fn map_managed_packages(
fn map_required(
packages: BTreeMap<String, Self::Options>,
_: &Config,
) -> Result<BTreeMap<String, Self::Options>> {
Expand Down Expand Up @@ -117,10 +117,10 @@ impl Backend for Cargo {
run_command_for_stdout(["cargo", "--version"], Perms::Same, false)
}

fn missing(managed: Self::Options, installed: Option<Self::Options>) -> Option<Self::Options> {
fn missing(required: Self::Options, installed: Option<Self::Options>) -> Option<Self::Options> {
match installed {
Some(_) => None,
None => Some(managed),
None => Some(required),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/backends/dnf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct DnfOptions {
impl Backend for Dnf {
type Options = DnfOptions;

fn map_managed_packages(
fn map_required(
packages: BTreeMap<String, Self::Options>,
_: &Config,
) -> Result<BTreeMap<String, Self::Options>> {
Expand Down Expand Up @@ -129,10 +129,10 @@ impl Backend for Dnf {
run_command_for_stdout(["dnf", "--version"], Perms::Same, false)
}

fn missing(managed: Self::Options, installed: Option<Self::Options>) -> Option<Self::Options> {
fn missing(required: Self::Options, installed: Option<Self::Options>) -> Option<Self::Options> {
match installed {
Some(_) => None,
None => Some(managed),
None => Some(required),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/backends/flatpak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct FlatpakOptions {
impl Backend for Flatpak {
type Options = FlatpakOptions;

fn map_managed_packages(
fn map_required(
packages: BTreeMap<String, Self::Options>,
_: &Config,
) -> Result<BTreeMap<String, Self::Options>> {
Expand Down Expand Up @@ -202,10 +202,10 @@ impl Backend for Flatpak {
run_command_for_stdout(["flatpak", "--version"], Perms::Same, false)
}

fn missing(managed: Self::Options, installed: Option<Self::Options>) -> Option<Self::Options> {
fn missing(required: Self::Options, installed: Option<Self::Options>) -> Option<Self::Options> {
match installed {
Some(_) => None,
None => Some(managed),
None => Some(required),
}
}
}
4 changes: 2 additions & 2 deletions src/backends/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct StringPackageStruct {
pub trait Backend {
type Options;

fn map_managed_packages(
fn map_required(
packages: BTreeMap<String, Self::Options>,
config: &Config,
) -> Result<BTreeMap<String, Self::Options>>;
Expand All @@ -66,5 +66,5 @@ pub trait Backend {

fn version(config: &Config) -> Result<String>;

fn missing(managed: Self::Options, installed: Option<Self::Options>) -> Option<Self::Options>;
fn missing(required: Self::Options, installed: Option<Self::Options>) -> Option<Self::Options>;
}
6 changes: 3 additions & 3 deletions src/backends/pipx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct PipxOptions {}
impl Backend for Pipx {
type Options = PipxOptions;

fn map_managed_packages(
fn map_required(
packages: BTreeMap<String, Self::Options>,
_: &Config,
) -> Result<BTreeMap<String, Self::Options>> {
Expand Down Expand Up @@ -83,12 +83,12 @@ impl Backend for Pipx {
}

fn missing(
managed: Self::Options,
required: Self::Options,
installed: Option<Self::Options>,
) -> Option<Self::Options> {
match installed {
Some(_) => None,
None => Some(managed),
None => Some(required),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/backends/rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct RustupOptions {
impl Backend for Rustup {
type Options = RustupOptions;

fn map_managed_packages(
fn map_required(
packages: BTreeMap<String, Self::Options>,
_: &Config,
) -> Result<BTreeMap<String, Self::Options>> {
Expand Down Expand Up @@ -123,10 +123,10 @@ impl Backend for Rustup {
run_command_for_stdout(["rustup", "--version"], Perms::Same, true)
}

fn missing(managed: Self::Options, installed: Option<Self::Options>) -> Option<Self::Options> {
fn missing(required: Self::Options, installed: Option<Self::Options>) -> Option<Self::Options> {
match installed {
Some(installed) => {
let missing = managed
let missing = required
.components
.difference(&installed.components)
.cloned()
Expand All @@ -139,7 +139,7 @@ impl Backend for Rustup {
})
}
}
None => Some(managed),
None => Some(required),
}
}
}
6 changes: 3 additions & 3 deletions src/backends/snap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct SnapOptions {}
impl Backend for Snap {
type Options = SnapOptions;

fn map_managed_packages(
fn map_required(
packages: BTreeMap<String, Self::Options>,
_: &Config,
) -> Result<BTreeMap<String, Self::Options>> {
Expand Down Expand Up @@ -86,10 +86,10 @@ impl Backend for Snap {
})
}

fn missing(managed: Self::Options, installed: Option<Self::Options>) -> Option<Self::Options> {
fn missing(required: Self::Options, installed: Option<Self::Options>) -> Option<Self::Options> {
match installed {
Some(_) => None,
None => Some(managed),
None => Some(required),
}
}
}
6 changes: 3 additions & 3 deletions src/backends/winget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct WinGetOptions {}
impl Backend for WinGet {
type Options = WinGetOptions;

fn map_managed_packages(
fn map_required(
packages: BTreeMap<String, Self::Options>,
_: &Config,
) -> Result<BTreeMap<String, Self::Options>> {
Expand Down Expand Up @@ -102,12 +102,12 @@ impl Backend for WinGet {
}

fn missing(
managed: Self::Options,
required: Self::Options,
installed: Option<Self::Options>,
) -> Option<Self::Options> {
match installed {
Some(_) => None,
None => Some(managed),
None => Some(required),
}
}
}
6 changes: 3 additions & 3 deletions src/backends/xbps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct XbpsOptions {}
impl Backend for Xbps {
type Options = XbpsOptions;

fn map_managed_packages(
fn map_required(
packages: BTreeMap<String, Self::Options>,
_: &Config,
) -> Result<BTreeMap<String, Self::Options>> {
Expand Down Expand Up @@ -96,12 +96,12 @@ impl Backend for Xbps {
}

fn missing(
managed: Self::Options,
required: Self::Options,
installed: Option<Self::Options>,
) -> Option<Self::Options> {
match installed {
Some(_) => None,
None => Some(managed),
None => Some(required),
}
}
}
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct SyncCommand {

#[derive(Args)]
#[command(visible_alias("u"))]
/// show explicitly installed packages not managed by metapac
/// show explicitly installed packages not required by metapac
///
/// the output is in valid toml group file format to allow writing
/// the output to a file which can help in importing packages
Expand Down
32 changes: 16 additions & 16 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ impl MainArguments {
let groups = Groups::load(&group_dir, &hostname, &config)
.wrap_err("failed to load package install options from groups")?;

let managed = groups.to_options().map_managed_packages(&config)?;
let required = groups.to_options().map_required(&config)?;

match self.subcommand {
MainSubcommand::Clean(clean) => clean.run(&managed, &config),
MainSubcommand::Clean(clean) => clean.run(&required, &config),
MainSubcommand::Add(add) => add.run(&group_dir, &groups),
MainSubcommand::Review(review) => review.run(&managed, &config),
MainSubcommand::Sync(sync) => sync.run(&managed, &config),
MainSubcommand::Unmanaged(unmanaged) => unmanaged.run(&managed, &config),
MainSubcommand::Review(review) => review.run(&required, &config),
MainSubcommand::Sync(sync) => sync.run(&required, &config),
MainSubcommand::Unmanaged(unmanaged) => unmanaged.run(&required, &config),
MainSubcommand::Backends(found_backends) => found_backends.run(&config),
MainSubcommand::CleanCache(backends) => backends.run(&config),
}
}
}

impl CleanCommand {
fn run(self, managed: &Options, config: &Config) -> Result<()> {
let unmanaged = unmanaged(managed, config)?;
fn run(self, required: &Options, config: &Config) -> Result<()> {
let unmanaged = unmanaged(required, config)?;

if unmanaged.is_empty() {
eprintln!("nothing to clean since there are no unmanaged packages");
Expand Down Expand Up @@ -133,8 +133,8 @@ impl ReviewCommand {
}

impl SyncCommand {
fn run(self, managed: &Options, config: &Config) -> Result<()> {
let missing = missing(managed, config)?;
fn run(self, required: &Options, config: &Config) -> Result<()> {
let missing = missing(required, config)?;

if missing.is_empty() {
log::info!("nothing to do as there are no missing packages");
Expand Down Expand Up @@ -162,8 +162,8 @@ impl SyncCommand {
}

impl UnmanagedCommand {
fn run(self, managed: &Options, config: &Config) -> Result<()> {
let unmanaged = unmanaged(managed, config)?;
fn run(self, required: &Options, config: &Config) -> Result<()> {
let unmanaged = unmanaged(required, config)?;

if unmanaged.is_empty() {
eprintln!("no unmanaged packages");
Expand Down Expand Up @@ -217,21 +217,21 @@ impl CleanCacheCommand {
}
}

fn unmanaged(managed: &Options, config: &Config) -> Result<PackageIds> {
fn unmanaged(required: &Options, config: &Config) -> Result<PackageIds> {
Options::query(config)
.map(|x| x.to_package_ids().difference(&managed.to_package_ids()))
.map(|x| x.to_package_ids().difference(&required.to_package_ids()))
}
fn missing(managed: &Options, config: &Config) -> Result<Options> {
fn missing(required: &Options, config: &Config) -> Result<Options> {
let installed = Options::query(config)?;

let mut missing = Options::default();

macro_rules! x {
($(($upper_backend:ident, $lower_backend:ident)),*) => {
$(
for (package_id, managed_options) in managed.$lower_backend.iter() {
for (package_id, required_options) in required.$lower_backend.iter() {
if let Some(missing_options) =
$upper_backend::missing(managed_options.clone(), installed.$lower_backend.get(package_id).cloned())
$upper_backend::missing(required_options.clone(), installed.$lower_backend.get(package_id).cloned())
{
missing.$lower_backend.insert(package_id.clone(), missing_options);
}
Expand Down

0 comments on commit e469a27

Please sign in to comment.