feat(git): started work on using spinners

Spinners are a blinking lights UX component. Ideally, a flag will be
added to run silently.

This only implements a sketch for using spinners when doing a quick
sync.

Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
Christina Sørensen 2023-06-29 12:05:59 +02:00
parent 58b9c50b83
commit b6e04cf4a4
Signed by: cafkafk
GPG key ID: CDDC792F655251ED
4 changed files with 92 additions and 17 deletions

67
Cargo.lock generated
View file

@ -129,7 +129,7 @@ dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
"syn 2.0.18",
]
[[package]]
@ -199,6 +199,7 @@ dependencies = [
"relative-path",
"serde",
"serde_yaml",
"spinners",
]
[[package]]
@ -276,6 +277,12 @@ version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6"
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.144"
@ -297,6 +304,12 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "maplit"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d"
[[package]]
name = "memchr"
version = "2.5.0"
@ -386,6 +399,12 @@ dependencies = [
"windows-sys",
]
[[package]]
name = "rustversion"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06"
[[package]]
name = "ryu"
version = "1.0.13"
@ -409,7 +428,7 @@ checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.18",
]
[[package]]
@ -425,12 +444,56 @@ dependencies = [
"unsafe-libyaml",
]
[[package]]
name = "spinners"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08615eea740067d9899969bc2891c68a19c315cb1f66640af9a9ecb91b13bcab"
dependencies = [
"lazy_static",
"maplit",
"strum",
]
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "strum"
version = "0.24.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f"
dependencies = [
"strum_macros",
]
[[package]]
name = "strum_macros"
version = "0.24.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59"
dependencies = [
"heck",
"proc-macro2",
"quote",
"rustversion",
"syn 1.0.109",
]
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "syn"
version = "2.0.18"

View file

@ -16,6 +16,7 @@ log = "0.4"
#env_logger = "0.9"
pretty_env_logger = "0.4"
relative-path = "1.8.0"
spinners = "4.1.0"
[build-dependencies]
clap = { version = "4.3.2", features = ["derive", "cargo", "env", "help"] }

View file

@ -1,3 +1,3 @@
#!/usr/bin/env bash
cargo rustc
cargo install --path .
# cargo rustc
cargo install --debug --path .

View file

@ -16,6 +16,7 @@
use log::{debug, error, info, trace, warn};
use serde::{Deserialize, Serialize};
use spinners::{Spinner, Spinners};
use std::collections::HashMap;
use std::fs::canonicalize;
use std::os::unix::fs::symlink;
@ -24,6 +25,9 @@ use std::{fs, process::Command};
// why not make it O(log n) instead of a vec that's /only/ O(n)
// ...because premature optimization is the root of all evil!
//
// it's time
#[derive(PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize, Debug)]
pub enum RepoFlags {
Push,
@ -41,6 +45,9 @@ pub struct Config {
pub links: Vec<Links>,
}
/// Represents a category of repositories
///
/// This allows you to organize your repositories into categories
#[derive(PartialEq, Debug, Serialize, Deserialize)]
pub struct Category {
pub flags: Vec<RepoFlags>, // FIXME: not implemented
@ -120,9 +127,9 @@ impl GitRepo {
.arg("clone")
.arg(&self.url)
.arg(&self.name)
.status()
.output()
.unwrap_or_else(|_| panic!("git repo failed to clone: {:?}", &self,));
info!("{out}");
// info!("{out}");
} else {
info!("{} has clone set to false, not cloned", &self.name);
}
@ -132,9 +139,9 @@ impl GitRepo {
let out = Command::new("git")
.current_dir(format!("{}{}", &self.path, &self.name))
.arg("pull")
.status()
.output()
.unwrap_or_else(|_| panic!("git repo failed to pull: {:?}", &self,));
info!("{out}");
// info!("{out}");
}
/// Adds all files in the repository.
fn add_all(&self) {
@ -143,9 +150,9 @@ impl GitRepo {
.current_dir(format!("{}{}", &self.path, &self.name))
.arg("add")
.arg(".")
.status()
.output()
.unwrap_or_else(|_| panic!("git repo failed to add: {:?}", &self,));
info!("{out}");
// info!("{out}");
} else {
info!("{} has clone set to false, not cloned", &self.name);
}
@ -157,9 +164,9 @@ impl GitRepo {
let out = Command::new("git")
.current_dir(format!("{}{}", &self.path, &self.name))
.arg("commit")
.status()
.output()
.unwrap_or_else(|_| panic!("git repo failed to commit: {:?}", &self,));
info!("{out}");
// info!("{out}");
} else {
info!("{} has clone set to false, not cloned", &self.name);
}
@ -172,9 +179,9 @@ impl GitRepo {
.arg("commit")
.arg("-m")
.arg(msg)
.status()
.output()
.unwrap_or_else(|_| panic!("git repo failed to commit: {:?}", &self,));
info!("{out}");
// info!("{out}");
} else {
info!("{} has clone set to false, not cloned", &self.name);
}
@ -185,9 +192,9 @@ impl GitRepo {
let out = Command::new("git")
.current_dir(format!("{}{}", &self.path, &self.name))
.arg("push")
.status()
.output()
.unwrap_or_else(|_| panic!("git repo failed to push: {:?}", &self,));
info!("{out}");
// info!("{out}");
} else {
info!("{} has clone set to false, not cloned", &self.name);
}
@ -224,7 +231,6 @@ impl Config {
F: Fn(&GitRepo),
{
for (_, category) in self.categories.iter() {
println!("{category:?}");
for (_, repo) in category.repos.iter() {
f(repo);
}
@ -270,10 +276,15 @@ impl Config {
pub fn quick(&self, msg: &String) {
debug!("exectuting quick");
self.on_all(|repo| {
let mut sp = Spinner::new(Spinners::Dots10, format!("{}: pull", repo.name).into());
repo.pull();
sp = Spinner::new(Spinners::Dots10, format!("{}: add_all", repo.name).into());
repo.add_all();
sp = Spinner::new(Spinners::Dots10, format!("{}: commit", repo.name).into());
repo.commit_with_msg(msg);
sp = Spinner::new(Spinners::Dots10, format!("{}: push", repo.name).into());
repo.push();
sp.stop_and_persist("", format!("{}: quick", repo.name).into());
});
}