Skip to content

Commit

Permalink
feat: add no progress
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle committed Dec 15, 2024
1 parent fe220af commit 2b2cf70
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ struct Args {
/// Verify hash of folder / file once copied
#[arg(long)]
verify: bool,

/// Disable progress bar
#[arg(long)]
no_progress: bool,

}

fn main() -> Result<()> {
Expand Down Expand Up @@ -63,6 +68,7 @@ fn main() -> Result<()> {
}

// Set up progress handler
#[allow(unused)]
let dir_progress_handler = |info: fs_extra::dir::TransitProcess| {
tracing::info!(
"Progress: {}% ({}/{})",
Expand All @@ -87,6 +93,7 @@ fn main() -> Result<()> {
}
};

#[allow(unused)]
let file_progress_handler = |info: fs_extra::file::TransitProcess| {
tracing::info!(
"Progress: {}% ({}/{})",
Expand All @@ -102,12 +109,21 @@ fn main() -> Result<()> {
let mut options = CopyOptions::new();
options.overwrite = args.force;
options.copy_inside = true;
dir::copy_with_progress(
source_path,
destination_path,
&options,
dir_progress_handler,
)?;
if args.no_progress {
dir::copy(
source_path,
destination_path,
&options,
)?;
} else {
dir::copy_with_progress(
source_path,
destination_path,
&options,
dir_progress_handler,
)?;
}

} else {
if destination_path.exists() && !args.force {
bail!("Fail already exists at {}", destination_path.display())
Expand All @@ -122,12 +138,21 @@ fn main() -> Result<()> {
} else {
let mut file_options = fs_extra::file::CopyOptions::new();
file_options.overwrite = args.force;
fs_extra::file::copy_with_progress(
source_path,
destination_path,
&file_options,
file_progress_handler,
)?;
if args.no_progress {
fs_extra::file::copy(
source_path,
destination_path,
&file_options,
)?;
} else {
fs_extra::file::copy_with_progress(
source_path,
destination_path,
&file_options,
file_progress_handler,
)?;
}

}
}

Expand Down

0 comments on commit 2b2cf70

Please sign in to comment.