refactor: code quality improvements
Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
parent
78f3aa5a1d
commit
81c2821c8c
2 changed files with 11 additions and 12 deletions
20
src/git.rs
20
src/git.rs
|
@ -186,10 +186,10 @@ impl Repo {
|
||||||
{
|
{
|
||||||
// TODO: check if &self.name.as_ref() already exists in dir
|
// TODO: check if &self.name.as_ref() already exists in dir
|
||||||
let output = Command::new("git")
|
let output = Command::new("git")
|
||||||
.current_dir(&self.path.as_ref().unwrap())
|
.current_dir(self.path.as_ref().unwrap())
|
||||||
.arg("clone")
|
.arg("clone")
|
||||||
.arg(&self.url.as_ref().unwrap())
|
.arg(self.url.as_ref().unwrap())
|
||||||
.arg(&self.name.as_ref().unwrap())
|
.arg(self.name.as_ref().unwrap())
|
||||||
.output()
|
.output()
|
||||||
.unwrap_or_else(|_| panic!("git repo failed to clone: {:?}", &self,));
|
.unwrap_or_else(|_| panic!("git repo failed to clone: {:?}", &self,));
|
||||||
output.status.success()
|
output.status.success()
|
||||||
|
@ -618,7 +618,7 @@ impl Config {
|
||||||
|
|
||||||
for category in self.categories.values() {
|
for category in self.categories.values() {
|
||||||
// HACK: if the repo doesn't exist here, we inject tmp
|
// HACK: if the repo doesn't exist here, we inject tmp
|
||||||
for (_, repo) in category.repos.as_ref().unwrap_or_else(|| &tmp).iter() {
|
for (_, repo) in category.repos.as_ref().unwrap_or(&tmp).iter() {
|
||||||
use RepoKinds::*;
|
use RepoKinds::*;
|
||||||
match &repo.kind {
|
match &repo.kind {
|
||||||
Some(GitRepo) => {
|
Some(GitRepo) => {
|
||||||
|
@ -650,10 +650,10 @@ impl Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
println!("unknown kind {:?}", repo.kind)
|
println!("unknown kind {:?}", repo.kind);
|
||||||
}
|
}
|
||||||
Some(kind) => {
|
Some(kind) => {
|
||||||
println!("unknown kind {kind:?}")
|
println!("unknown kind {kind:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -663,7 +663,7 @@ impl Config {
|
||||||
where
|
where
|
||||||
F: FnOnce(&Repo),
|
F: FnOnce(&Repo),
|
||||||
{
|
{
|
||||||
f(&self
|
f(self
|
||||||
.categories
|
.categories
|
||||||
.get(cat_name)
|
.get(cat_name)
|
||||||
.expect("failed to get category")
|
.expect("failed to get category")
|
||||||
|
@ -671,13 +671,13 @@ impl Config {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.expect("failed to get repo")
|
.expect("failed to get repo")
|
||||||
.get(repo_name)
|
.get(repo_name)
|
||||||
.expect("failed to get category"))
|
.expect("failed to get category"));
|
||||||
}
|
}
|
||||||
pub fn get_link<F>(&self, cat_name: &str, link_name: &str, f: F)
|
pub fn get_link<F>(&self, cat_name: &str, link_name: &str, f: F)
|
||||||
where
|
where
|
||||||
F: FnOnce(&Link),
|
F: FnOnce(&Link),
|
||||||
{
|
{
|
||||||
f(&self
|
f(self
|
||||||
.categories
|
.categories
|
||||||
.get(cat_name)
|
.get(cat_name)
|
||||||
.expect("failed to get category")
|
.expect("failed to get category")
|
||||||
|
@ -685,7 +685,7 @@ impl Config {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.expect("failed to get repo")
|
.expect("failed to get repo")
|
||||||
.get(link_name)
|
.get(link_name)
|
||||||
.expect("failed to get category"))
|
.expect("failed to get category"));
|
||||||
}
|
}
|
||||||
/// 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) {
|
||||||
|
|
|
@ -45,7 +45,6 @@ mod utils;
|
||||||
|
|
||||||
use cli::{Args, Commands, JumpCommands};
|
use cli::{Args, Commands, JumpCommands};
|
||||||
use git::Config;
|
use git::Config;
|
||||||
use utils::strings::{FAST_COMMIT, QUICK_COMMIT};
|
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
|
@ -65,7 +64,7 @@ fn main() {
|
||||||
|
|
||||||
// Input from -m flag is stored here, this is just used to construct the
|
// Input from -m flag is stored here, this is just used to construct the
|
||||||
// persistent box
|
// persistent box
|
||||||
let mut message_input: String = "".to_string();
|
let mut message_input: String = String::new();
|
||||||
|
|
||||||
match &args {
|
match &args {
|
||||||
args if args.license => println!("{}", utils::strings::INTERACTIVE_LICENSE),
|
args if args.license => println!("{}", utils::strings::INTERACTIVE_LICENSE),
|
||||||
|
|
Loading…
Reference in a new issue