refactor: renamed GitRepo to Repo
Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
parent
8cbff324e7
commit
93175124b8
2 changed files with 35 additions and 35 deletions
62
src/git.rs
62
src/git.rs
|
@ -85,7 +85,7 @@ pub struct Category {
|
||||||
///
|
///
|
||||||
/// Key should conceptually be seen as the name of the category.
|
/// Key should conceptually be seen as the name of the category.
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub repos: Option<HashMap<String, GitRepo>>,
|
pub repos: Option<HashMap<String, Repo>>,
|
||||||
|
|
||||||
/// map of all links in category
|
/// map of all links in category
|
||||||
///
|
///
|
||||||
|
@ -105,13 +105,13 @@ pub struct Link {
|
||||||
|
|
||||||
/// Holds a single git repository and related fields.
|
/// Holds a single git repository and related fields.
|
||||||
#[derive(Eq, PartialEq, Debug, Serialize, Deserialize)]
|
#[derive(Eq, PartialEq, Debug, Serialize, Deserialize)]
|
||||||
pub struct GitRepo {
|
pub struct Repo {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub path: String,
|
pub path: String,
|
||||||
pub url: String,
|
pub url: String,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub kind: Option<RepoKinds>, // FIXME: not implemented
|
||||||
pub flags: Option<Vec<RepoFlags>>,
|
pub flags: Option<Vec<RepoFlags>>,
|
||||||
pub kind: Option<RepoKinds>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a single operation on a repository
|
/// Represents a single operation on a repository
|
||||||
|
@ -119,7 +119,7 @@ pub struct SeriesItem<'series> {
|
||||||
/// The string to be displayed to the user
|
/// The string to be displayed to the user
|
||||||
pub operation: &'series str,
|
pub operation: &'series str,
|
||||||
/// The closure representing the actual operation
|
/// The closure representing the actual operation
|
||||||
pub closure: Box<dyn Fn(&GitRepo) -> (bool)>,
|
pub closure: Box<dyn Fn(&Repo) -> (bool)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_file_exists(selff: &Link, tx_path: &Path, rx_path: &Path) -> bool {
|
fn handle_file_exists(selff: &Link, tx_path: &Path, rx_path: &Path) -> bool {
|
||||||
|
@ -174,7 +174,7 @@ impl Link {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GitRepo {
|
impl Repo {
|
||||||
/// Clones the repository to its specified folder.
|
/// Clones the repository to its specified folder.
|
||||||
pub fn clone(&self) -> bool {
|
pub fn clone(&self) -> bool {
|
||||||
if self
|
if self
|
||||||
|
@ -361,7 +361,7 @@ impl Config {
|
||||||
/// NOTE: currently unused
|
/// NOTE: currently unused
|
||||||
fn on_all<F>(&self, f: F)
|
fn on_all<F>(&self, f: F)
|
||||||
where
|
where
|
||||||
F: Fn(&GitRepo),
|
F: Fn(&Repo),
|
||||||
{
|
{
|
||||||
for category in self.categories.values() {
|
for category in self.categories.values() {
|
||||||
for (_, repo) in category.repos.as_ref().expect("failed to get repos").iter() {
|
for (_, repo) in category.repos.as_ref().expect("failed to get repos").iter() {
|
||||||
|
@ -372,7 +372,7 @@ impl Config {
|
||||||
// /// Runs associated function on all repos in config
|
// /// Runs associated function on all repos in config
|
||||||
// fn on_all_spinner<F>(&self, op: &str, f: F)
|
// fn on_all_spinner<F>(&self, op: &str, f: F)
|
||||||
// where
|
// where
|
||||||
// F: Fn(&GitRepo) -> bool,
|
// F: Fn(&Repo) -> bool,
|
||||||
// {
|
// {
|
||||||
// for category in self.categories.values() {
|
// for category in self.categories.values() {
|
||||||
// for (_, repo) in category.repos.as_ref().expect("failed to get repos").iter() {
|
// for (_, repo) in category.repos.as_ref().expect("failed to get repos").iter() {
|
||||||
|
@ -392,7 +392,7 @@ impl Config {
|
||||||
/// Runs associated function on all repos in config
|
/// Runs associated function on all repos in config
|
||||||
fn on_all_repos_spinner<F>(&self, op: &str, f: F)
|
fn on_all_repos_spinner<F>(&self, op: &str, f: F)
|
||||||
where
|
where
|
||||||
F: Fn(&GitRepo) -> bool,
|
F: Fn(&Repo) -> bool,
|
||||||
{
|
{
|
||||||
for category in self.categories.values() {
|
for category in self.categories.values() {
|
||||||
match category.repos.as_ref() {
|
match category.repos.as_ref() {
|
||||||
|
@ -469,24 +469,24 @@ impl Config {
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use gg::git::SeriesItem;
|
/// # use gg::git::SeriesItem;
|
||||||
/// # use gg::git::GitRepo;
|
/// # use gg::git::Repo;
|
||||||
///
|
///
|
||||||
/// let series: Vec<SeriesItem> = vec![
|
/// let series: Vec<SeriesItem> = vec![
|
||||||
/// SeriesItem {
|
/// SeriesItem {
|
||||||
/// operation: "pull",
|
/// operation: "pull",
|
||||||
/// closure: Box::new(move |repo: &GitRepo| repo.pull()),
|
/// closure: Box::new(move |repo: &Repo| repo.pull()),
|
||||||
/// },
|
/// },
|
||||||
/// SeriesItem {
|
/// SeriesItem {
|
||||||
/// operation: "add",
|
/// operation: "add",
|
||||||
/// closure: Box::new(move |repo: &GitRepo| repo.add_all()),
|
/// closure: Box::new(move |repo: &Repo| repo.add_all()),
|
||||||
/// },
|
/// },
|
||||||
/// SeriesItem {
|
/// SeriesItem {
|
||||||
/// operation: "commit",
|
/// operation: "commit",
|
||||||
/// closure: Box::new(move |repo: &GitRepo| repo.commit()),
|
/// closure: Box::new(move |repo: &Repo| repo.commit()),
|
||||||
/// },
|
/// },
|
||||||
/// SeriesItem {
|
/// SeriesItem {
|
||||||
/// operation: "push",
|
/// operation: "push",
|
||||||
/// closure: Box::new(move |repo: &GitRepo| repo.push()),
|
/// closure: Box::new(move |repo: &Repo| repo.push()),
|
||||||
/// },
|
/// },
|
||||||
/// ];
|
/// ];
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -521,25 +521,25 @@ impl Config {
|
||||||
/// Here is an example of how an associated method could use this function.
|
/// Here is an example of how an associated method could use this function.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use gg::git::GitRepo;
|
/// # use gg::git::Repo;
|
||||||
/// # use gg::git::SeriesItem;
|
/// # use gg::git::SeriesItem;
|
||||||
///
|
///
|
||||||
/// let series: Vec<SeriesItem> = vec![
|
/// let series: Vec<SeriesItem> = vec![
|
||||||
/// SeriesItem {
|
/// SeriesItem {
|
||||||
/// operation: "pull",
|
/// operation: "pull",
|
||||||
/// closure: Box::new(move |repo: &GitRepo| repo.pull()),
|
/// closure: Box::new(move |repo: &Repo| repo.pull()),
|
||||||
/// },
|
/// },
|
||||||
/// SeriesItem {
|
/// SeriesItem {
|
||||||
/// operation: "add",
|
/// operation: "add",
|
||||||
/// closure: Box::new(move |repo: &GitRepo| repo.add_all()),
|
/// closure: Box::new(move |repo: &Repo| repo.add_all()),
|
||||||
/// },
|
/// },
|
||||||
/// SeriesItem {
|
/// SeriesItem {
|
||||||
/// operation: "commit",
|
/// operation: "commit",
|
||||||
/// closure: Box::new(move |repo: &GitRepo| repo.commit()),
|
/// closure: Box::new(move |repo: &Repo| repo.commit()),
|
||||||
/// },
|
/// },
|
||||||
/// SeriesItem {
|
/// SeriesItem {
|
||||||
/// operation: "push",
|
/// operation: "push",
|
||||||
/// closure: Box::new(move |repo: &GitRepo| repo.push()),
|
/// closure: Box::new(move |repo: &Repo| repo.push()),
|
||||||
/// },
|
/// },
|
||||||
/// ];
|
/// ];
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -566,7 +566,7 @@ impl Config {
|
||||||
}
|
}
|
||||||
pub fn get_repo<F>(&self, cat_name: &str, repo_name: &str, f: F)
|
pub fn get_repo<F>(&self, cat_name: &str, repo_name: &str, f: F)
|
||||||
where
|
where
|
||||||
F: FnOnce(&GitRepo),
|
F: FnOnce(&Repo),
|
||||||
{
|
{
|
||||||
f(&self
|
f(&self
|
||||||
.categories
|
.categories
|
||||||
|
@ -595,22 +595,22 @@ impl Config {
|
||||||
/// Tries to pull all repositories, skips if fail.
|
/// Tries to pull all repositories, skips if fail.
|
||||||
pub fn pull_all(&self) {
|
pub fn pull_all(&self) {
|
||||||
debug!("exectuting pull_all");
|
debug!("exectuting pull_all");
|
||||||
self.on_all_repos_spinner("pull", GitRepo::pull);
|
self.on_all_repos_spinner("pull", Repo::pull);
|
||||||
}
|
}
|
||||||
/// Tries to clone all repossitories, skips if fail.
|
/// Tries to clone all repossitories, skips if fail.
|
||||||
pub fn clone_all(&self) {
|
pub fn clone_all(&self) {
|
||||||
debug!("exectuting clone_all");
|
debug!("exectuting clone_all");
|
||||||
self.on_all_repos_spinner("clone", GitRepo::clone);
|
self.on_all_repos_spinner("clone", Repo::clone);
|
||||||
}
|
}
|
||||||
/// Tries to add all work in all repossitories, skips if fail.
|
/// Tries to add all work in all repossitories, skips if fail.
|
||||||
pub fn add_all(&self) {
|
pub fn add_all(&self) {
|
||||||
debug!("exectuting clone_all");
|
debug!("exectuting clone_all");
|
||||||
self.on_all_repos_spinner("add", GitRepo::add_all);
|
self.on_all_repos_spinner("add", Repo::add_all);
|
||||||
}
|
}
|
||||||
/// Tries to commit all repossitories one at a time, skips if fail.
|
/// Tries to commit all repossitories one at a time, skips if fail.
|
||||||
pub fn commit_all(&self) {
|
pub fn commit_all(&self) {
|
||||||
debug!("exectuting clone_all");
|
debug!("exectuting clone_all");
|
||||||
self.on_all_repos_spinner("commit", GitRepo::commit);
|
self.on_all_repos_spinner("commit", Repo::commit);
|
||||||
}
|
}
|
||||||
/// Tries to commit all repossitories with msg, skips if fail.
|
/// Tries to commit all repossitories with msg, skips if fail.
|
||||||
pub fn commit_all_msg(&self, msg: &str) {
|
pub fn commit_all_msg(&self, msg: &str) {
|
||||||
|
@ -624,19 +624,19 @@ impl Config {
|
||||||
let series: Vec<SeriesItem> = vec![
|
let series: Vec<SeriesItem> = vec![
|
||||||
SeriesItem {
|
SeriesItem {
|
||||||
operation: "pull",
|
operation: "pull",
|
||||||
closure: Box::new(GitRepo::pull),
|
closure: Box::new(Repo::pull),
|
||||||
},
|
},
|
||||||
SeriesItem {
|
SeriesItem {
|
||||||
operation: "add",
|
operation: "add",
|
||||||
closure: Box::new(GitRepo::add_all),
|
closure: Box::new(Repo::add_all),
|
||||||
},
|
},
|
||||||
SeriesItem {
|
SeriesItem {
|
||||||
operation: "commit",
|
operation: "commit",
|
||||||
closure: Box::new(move |repo: &GitRepo| repo.commit_with_msg(msg)),
|
closure: Box::new(move |repo: &Repo| repo.commit_with_msg(msg)),
|
||||||
},
|
},
|
||||||
SeriesItem {
|
SeriesItem {
|
||||||
operation: "push",
|
operation: "push",
|
||||||
closure: Box::new(GitRepo::push),
|
closure: Box::new(Repo::push),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
//self.all_on_all(series);
|
//self.all_on_all(series);
|
||||||
|
@ -649,19 +649,19 @@ impl Config {
|
||||||
let series: Vec<SeriesItem> = vec![
|
let series: Vec<SeriesItem> = vec![
|
||||||
SeriesItem {
|
SeriesItem {
|
||||||
operation: "pull",
|
operation: "pull",
|
||||||
closure: Box::new(GitRepo::pull),
|
closure: Box::new(Repo::pull),
|
||||||
},
|
},
|
||||||
SeriesItem {
|
SeriesItem {
|
||||||
operation: "add",
|
operation: "add",
|
||||||
closure: Box::new(GitRepo::add_all),
|
closure: Box::new(Repo::add_all),
|
||||||
},
|
},
|
||||||
SeriesItem {
|
SeriesItem {
|
||||||
operation: "commit",
|
operation: "commit",
|
||||||
closure: Box::new(move |repo: &GitRepo| repo.commit_with_msg(msg)),
|
closure: Box::new(move |repo: &Repo| repo.commit_with_msg(msg)),
|
||||||
},
|
},
|
||||||
SeriesItem {
|
SeriesItem {
|
||||||
operation: "push",
|
operation: "push",
|
||||||
closure: Box::new(GitRepo::push),
|
closure: Box::new(Repo::push),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
self.series_on_all(series);
|
self.series_on_all(series);
|
||||||
|
|
|
@ -162,7 +162,7 @@ fn main() {
|
||||||
mod config {
|
mod config {
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use git::RepoFlags::{Clone, Push};
|
use git::RepoFlags::{Clone, Push};
|
||||||
use git::{Category, GitRepo};
|
use git::{Category, Repo};
|
||||||
use relative_path::RelativePath;
|
use relative_path::RelativePath;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::env::current_dir;
|
use std::env::current_dir;
|
||||||
|
@ -197,7 +197,7 @@ mod config {
|
||||||
.expect("failed to get repo")
|
.expect("failed to get repo")
|
||||||
.insert(
|
.insert(
|
||||||
format!("{}", i).to_string(),
|
format!("{}", i).to_string(),
|
||||||
GitRepo {
|
Repo {
|
||||||
name: "test repo".to_string(),
|
name: "test repo".to_string(),
|
||||||
path: "/tmp".to_string(),
|
path: "/tmp".to_string(),
|
||||||
url: "https://github.com/cafkafk/gg".to_string(),
|
url: "https://github.com/cafkafk/gg".to_string(),
|
||||||
|
@ -275,7 +275,7 @@ mod config {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod repo_actions {
|
mod repo_actions {
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use git::GitRepo;
|
use git::Repo;
|
||||||
use relative_path::RelativePath;
|
use relative_path::RelativePath;
|
||||||
use std::env::current_dir;
|
use std::env::current_dir;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
@ -295,7 +295,7 @@ mod repo_actions {
|
||||||
repos: vec![],
|
repos: vec![],
|
||||||
links: vec![],
|
links: vec![],
|
||||||
};
|
};
|
||||||
let repo = GitRepo {
|
let repo = Repo {
|
||||||
name: test_repo_name.to_owned(),
|
name: test_repo_name.to_owned(),
|
||||||
path: test_repo_dir.to_owned(),
|
path: test_repo_dir.to_owned(),
|
||||||
url: test_repo_url.to_owned(),
|
url: test_repo_url.to_owned(),
|
||||||
|
|
Loading…
Reference in a new issue