Skip to content

Commit

Permalink
Merge pull request #914 from winpax/gix-progress
Browse files Browse the repository at this point in the history
Added prodash support for progress
  • Loading branch information
jewlexx authored Dec 11, 2024
2 parents 1d4fe5d + 787ffd6 commit e2c4ccd
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 78 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Warnings in search command for deprecated usage
- Support `json` flag in `search` command
- Warning to help message for `json` flag calling out that it only works for certain commands
- Progress reporting for `bucket add` command when not using `git` command

### Changed

Expand All @@ -27,6 +28,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Download hash checks now report to a progress bar rather than a print message for each
- Logs will now go into `<PWD>/logs` if running with debug assertions
- `search` command no longer hides `[installed]` label if only searching for installed apps
- Removed `disable_git` flag from `bucket add` command
- `bucket add` command now always uses gitoxide to clone the bucket

### Removed

Expand Down
100 changes: 95 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ konst = "0.3"
log = { version = "0.4", features = ["std"] }
open = "5.1"
parking_lot = "0.12"
prodash = { version = "29.0.0", features = [
"render-line",
"render-line-crossterm",
] }
quork = "0.8"
rand = "0.8.5"
ratatui = { version = "0.29", features = ["macros"] }
rayon = "1.10"
regex = "1.10"
Expand Down
83 changes: 19 additions & 64 deletions src/commands/bucket/add.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
use std::time::Duration;

use tokio::process::Command;

use anyhow::Context;
use clap::Parser;
use sprinkles::{contexts::ScoopContext, progress::indicatif};
use sprinkles::contexts::ScoopContext;

use crate::{abandon, calm_panic::CalmUnwrap};
use crate::abandon;

#[derive(Debug, Clone, Parser)]
/// Add a bucket
Expand All @@ -16,77 +11,37 @@ pub struct Args {

#[clap(help = "The url of the bucket to add")]
repo: Option<String>,

#[clap(from_global)]
disable_git: bool,
}

impl super::Command for Args {
async fn runner(self, ctx: &impl ScoopContext) -> anyhow::Result<()> {
let repo_url = self
.repo
.clone()
.context("No repo provided")
.unwrap_or_else(|_| {
let known_buckets = ctx.known_buckets();

if let Some(url) = known_buckets.get(&self.name) {
(*url).to_string()
} else {
abandon!(
"No bucket found with the name \"{}\". Try passing the url as well",
self.name
)
}
});
let repo_url = self.repo.clone().unwrap_or_else(|| {
let known_buckets = ctx.known_buckets();

if let Some(url) = known_buckets.get(&self.name) {
(*url).to_string()
} else {
abandon!(
"No bucket found with the name \"{}\". Try passing the url as well",
self.name
)
}
});

let dest_path = ctx.buckets_path().join(&self.name);

if dest_path.exists() {
abandon!("Bucket {name} already exists. Remove it first if you want to add it again: `sfsu bucket rm {name}`", name = self.name);
}

if self.disable_git {
let spinner = indicatif::ProgressBar::new_spinner();
spinner.set_message("Cloning repository");
spinner.enable_steady_tick(Duration::from_millis(100));

sprinkles::git::clone::clone(
&repo_url,
dest_path,
sprinkles::git::clone::progress::Discard,
)?;
let root = prodash::tree::Root::new();
let handle = crate::progress::render::LineRenderer::run(root.clone(), true);

spinner.finish_with_message("✅ Repository cloned");
} else {
let git_path = sprinkles::git::which().calm_expect("git not found");
let clone_progress = root.add_child_with_id("Cloning repository", *b"REPO");

let exit_status = Command::new(git_path)
.current_dir(ctx.buckets_path())
.arg("clone")
.arg(repo_url)
.arg(self.name)
.spawn()?
.wait_with_output()
.await?;
sprinkles::git::clone::clone(&repo_url, dest_path, clone_progress)?;

match exit_status.status.code() {
Some(0) => {}
Some(code) => {
return Err(anyhow::anyhow!(
"git exited with code {}.\nOutput:\n{}",
code,
String::from_utf8_lossy(&exit_status.stdout)
))
}
None => {
return Err(anyhow::anyhow!(
"git exited without a status code.\nOutput:\n{}",
String::from_utf8_lossy(&exit_status.stdout)
))
}
}
};
handle.await?;

Ok(())
}
Expand Down
Loading

0 comments on commit e2c4ccd

Please sign in to comment.