Skip to content

Commit

Permalink
refactor: 🚚 Reorganize package and repository actions into separate m…
Browse files Browse the repository at this point in the history
…odules
  • Loading branch information
pvshvp-oss committed Apr 8, 2024
1 parent 6c7d9e9 commit b46d9f7
Show file tree
Hide file tree
Showing 17 changed files with 259 additions and 83 deletions.
76 changes: 4 additions & 72 deletions paxy/src/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,94 +3,26 @@
pub enum Error {
#[non_exhaustive]
#[snafu(display("Could not list:\n {source}"))]
CouldNotList { source: list::Error },
PackageError { source: package::Error },

#[non_exhaustive]
#[snafu(display("Could not search:\n {source}"))]
CouldNotSearch { source: search::Error },

#[non_exhaustive]
#[snafu(display("Could not install:\n {source}"))]
CouldNotInstall { source: install::Error },

#[non_exhaustive]
#[snafu(display("Could not update:\n {source}"))]
CouldNotUpdate { source: update::Error },

#[non_exhaustive]
#[snafu(display("Could not uninstall:\n {source}"))]
CouldNotUninstall { source: uninstall::Error },

#[non_exhaustive]
#[snafu(display("Could not downgrade:\n {source}"))]
CouldNotDowngrade { source: downgrade::Error },
RepositoryError { source: repository::Error },
}

// region: IMPORTS

use std::path::PathBuf;

use snafu::Snafu;

// endregion: IMPORTS

// region: MODULES

pub mod add_repo;
pub mod downgrade;
pub mod install;
pub mod list;
pub mod rm_repo;
pub mod search;
pub mod uninstall;
pub mod update;
pub mod package;
pub mod repository;

// endregion: MODULES

// region: RE-EXPORTS

#[allow(unused_imports)]
pub use downgrade::*;
#[allow(unused_imports)]
pub use install::*;
#[allow(unused_imports)]
pub use list::*;
#[allow(unused_imports)]
pub use search::*;
#[allow(unused_imports)]
pub use uninstall::*;
#[allow(unused_imports)]
pub use update::*;

// endregion: RE-EXPORTS
#[macro_export]
macro_rules! home {
() => {
match home::home_dir() {
Some(path) => path,
None => panic!("Impossible to get your home dir!"),
}
};
}

#[inline]
pub fn ensure_path(path: Option<&PathBuf>) {
if path.is_none() {
let mut file = home!();
file.push(".paxy");
if !file.is_dir() {
::std::fs::create_dir_all(file).expect("Inufficient permissions");
}
} else {
if !path
.unwrap()
.is_dir()
{
::std::fs::create_dir_all(
path.unwrap()
.clone(),
)
.expect("Inufficient permissions");
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
64 changes: 64 additions & 0 deletions paxy/src/actions/package/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#[derive(Debug, Snafu)]
#[non_exhaustive]
pub enum Error {
#[non_exhaustive]
#[snafu(display("Could not list:\n {source}"))]
CouldNotList { source: list::Error },

#[non_exhaustive]
#[snafu(display("Could not search:\n {source}"))]
CouldNotSearch { source: search::Error },

#[non_exhaustive]
#[snafu(display("Could not install:\n {source}"))]
CouldNotInstall { source: install::Error },

#[non_exhaustive]
#[snafu(display("Could not update:\n {source}"))]
CouldNotUpdate { source: update::Error },

#[non_exhaustive]
#[snafu(display("Could not uninstall:\n {source}"))]
CouldNotUninstall { source: uninstall::Error },

#[non_exhaustive]
#[snafu(display("Could not downgrade:\n {source}"))]
CouldNotDowngrade { source: downgrade::Error },
}

// region: IMPORTS

use std::path::PathBuf;

use snafu::Snafu;

// endregion: IMPORTS

// region: MODULES

pub mod downgrade;
pub mod install;
pub mod list;
pub mod search;
pub mod uninstall;
pub mod update;

// endregion: MODULES

// region: RE-EXPORTS

#[allow(unused_imports)]
pub use downgrade::*;
#[allow(unused_imports)]
pub use install::*;
#[allow(unused_imports)]
pub use list::*;
#[allow(unused_imports)]
pub use search::*;
#[allow(unused_imports)]
pub use uninstall::*;
#[allow(unused_imports)]
pub use update::*;

// endregion: RE-EXPORTS

File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions paxy/src/actions/repository/downgrade.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#[derive(Debug, Snafu)]
#[non_exhaustive]
pub enum Error {
#[non_exhaustive]
#[snafu(display(""))]
Dummy {},
}

// region: IMPORTS

use snafu::Snafu;

// endregion: IMPORTS
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
use std::fs::{write, File};

use bson::{doc, Document};
use git2::Repository;
use log::{info, warn};

use crate::{actions::ensure_path, home};

#[allow(unused)]
fn add_repo(repo: &str, name: &str) {
let mut file = home!();
Expand Down Expand Up @@ -36,6 +28,36 @@ fn add_repo(repo: &str, name: &str) {
Repository::clone(repo, file).unwrap();
}

#[allow(dead_code)]
#[allow(unused_variables)]
fn plugin(manifest: PathBuf) -> PathBuf {
todo!()
}

#[derive(Debug, Snafu)]
#[non_exhaustive]
pub enum Error {
#[non_exhaustive]
#[snafu(display(""))]
Dummy {},
}

// region: IMPORTS

use std::{
fs::{write, File},
path::PathBuf,
};

use bson::{doc, Document};
use git2::Repository;
use log::{info, warn};
use snafu::Snafu;

// endregion: IMPORTS

// region: TESTS

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -53,3 +75,5 @@ mod tests {
);
}
}

// endregion: TESTS
13 changes: 13 additions & 0 deletions paxy/src/actions/repository/list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#[derive(Debug, Snafu)]
#[non_exhaustive]
pub enum Error {
#[non_exhaustive]
#[snafu(display(""))]
Dummy {},
}

// region: IMPORTS

use snafu::Snafu;

// endregion: IMPORTS
94 changes: 94 additions & 0 deletions paxy/src/actions/repository/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#[derive(Debug, Snafu)]
#[non_exhaustive]
pub enum Error {
#[non_exhaustive]
#[snafu(display("Could not list:\n {source}"))]
CouldNotList { source: list::Error },

#[non_exhaustive]
#[snafu(display("Could not search:\n {source}"))]
CouldNotSearch { source: search::Error },

#[non_exhaustive]
#[snafu(display("Could not install:\n {source}"))]
CouldNotInstall { source: install::Error },

#[non_exhaustive]
#[snafu(display("Could not update:\n {source}"))]
CouldNotUpdate { source: update::Error },

#[non_exhaustive]
#[snafu(display("Could not uninstall:\n {source}"))]
CouldNotUninstall { source: uninstall::Error },

#[non_exhaustive]
#[snafu(display("Could not downgrade:\n {source}"))]
CouldNotDowngrade { source: downgrade::Error },
}

// region: IMPORTS

use std::path::PathBuf;

use snafu::Snafu;

// endregion: IMPORTS

// region: MODULES

pub mod downgrade;
pub mod install;
pub mod list;
pub mod search;
pub mod uninstall;
pub mod update;

// endregion: MODULES

// region: RE-EXPORTS

#[allow(unused_imports)]
pub use downgrade::*;
#[allow(unused_imports)]
pub use install::*;
#[allow(unused_imports)]
pub use list::*;
#[allow(unused_imports)]
pub use search::*;
#[allow(unused_imports)]
pub use uninstall::*;
#[allow(unused_imports)]
pub use update::*;

// endregion: RE-EXPORTS
#[macro_export]
macro_rules! home {
() => {
match home::home_dir() {
Some(path) => path,
None => panic!("Impossible to get your home dir!"),
}
};
}

#[inline]
pub fn ensure_path(path: Option<&PathBuf>) {
if path.is_none() {
let mut file = home!();
file.push(".paxy");
if !file.is_dir() {
::std::fs::create_dir_all(file).expect("Inufficient permissions");
}
} else {
if !path
.unwrap()
.is_dir()
{
::std::fs::create_dir_all(
path.unwrap()
.clone(),
)
.expect("Inufficient permissions");
}
}
}
13 changes: 13 additions & 0 deletions paxy/src/actions/repository/search.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#[derive(Debug, Snafu)]
#[non_exhaustive]
pub enum Error {
#[non_exhaustive]
#[snafu(display(""))]
Dummy {},
}

// region: IMPORTS

use snafu::Snafu;

// endregion: IMPORTS
13 changes: 13 additions & 0 deletions paxy/src/actions/repository/uninstall.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#[derive(Debug, Snafu)]
#[non_exhaustive]
pub enum Error {
#[non_exhaustive]
#[snafu(display(""))]
Dummy {},
}

// region: IMPORTS

use snafu::Snafu;

// endregion: IMPORTS
13 changes: 13 additions & 0 deletions paxy/src/actions/repository/update.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#[derive(Debug, Snafu)]
#[non_exhaustive]
pub enum Error {
#[non_exhaustive]
#[snafu(display(""))]
Dummy {},
}

// region: IMPORTS

use snafu::Snafu;

// endregion: IMPORTS
1 change: 0 additions & 1 deletion paxy/src/actions/rm_repo.rs

This file was deleted.

2 changes: 0 additions & 2 deletions paxy/src/app/i18n.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
pub trait InitI18n {}

#[derive(Debug, Snafu)]
#[non_exhaustive]
pub enum Error {
Expand Down

0 comments on commit b46d9f7

Please sign in to comment.