Skip to content

Commit

Permalink
Console copy output formatting information update
Browse files Browse the repository at this point in the history
  • Loading branch information
abdolence committed Aug 13, 2024
1 parent 537572b commit 1b0e8ff
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 22 deletions.
60 changes: 45 additions & 15 deletions src/commands/copy_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::redacters::{
};
use crate::reporter::AppReporter;
use crate::AppResult;
use console::{Style, Term};
use console::{pad_str, Alignment, Style, Term};
use futures::Stream;
use gcloud_sdk::prost::bytes;
use indicatif::*;
Expand Down Expand Up @@ -118,12 +118,14 @@ pub async fn command_copy(
);

bar.set_length(files_found as u64);

let mut total_files_copied = 0;
let mut total_files_skipped = source_files_result.skipped;
for source_file in source_files {
match transfer_and_redact_file(
Some(&source_file),
term,
&bar,
Some(&source_file),
&mut source_fs,
&mut destination_fs,
&options,
Expand All @@ -142,8 +144,9 @@ pub async fn command_copy(
} else {
Ok(
match transfer_and_redact_file(
None,
term,
&bar,
None,
&mut source_fs,
&mut destination_fs,
&options,
Expand Down Expand Up @@ -178,8 +181,9 @@ async fn transfer_and_redact_file<
SFS: FileSystemConnection<'a>,
DFS: FileSystemConnection<'a>,
>(
source_file_ref: Option<&FileSystemRef>,
term: &Term,
bar: &ProgressBar,
source_file_ref: Option<&FileSystemRef>,
source_fs: &mut SFS,
destination_fs: &mut DFS,
options: &CopyCommandOptions,
Expand All @@ -202,18 +206,44 @@ async fn transfer_and_redact_file<
media_type: file_ref.media_type.clone(),
file_size: file_ref.file_size,
};
let max_filename_width = (term.width() as f64 * 0.25) as usize;
bar.println(
format!(
"Processing {} ({},{}) to {}. Size: {}",
bold_style.apply_to(&base_resolved_file_ref.file_path),
base_resolved_file_ref.scheme,
file_ref
.media_type
.as_ref()
.map(|media_type| media_type.to_string())
.unwrap_or_else(|| "unknown".to_string()),
bold_style.apply_to(destination_fs.resolve(Some(&dest_file_ref)).file_path),
bold_style.apply_to(HumanBytes(file_ref.file_size.unwrap_or(0)))
"Processing {} to {} {} Size: {}",
bold_style.apply_to(pad_str(
&base_resolved_file_ref.file_path,
max_filename_width,
Alignment::Left,
None
)),
bold_style.apply_to(pad_str(
destination_fs
.resolve(Some(&dest_file_ref))
.file_path
.as_str(),
max_filename_width,
Alignment::Left,
None
)),
pad_str(
file_ref
.media_type
.as_ref()
.map(|media_type| media_type.to_string())
.unwrap_or_else(|| "unknown".to_string())
.as_str(),
28,
Alignment::Left,
None
),
bold_style.apply_to(pad_str(
HumanBytes(file_ref.file_size.unwrap_or(0))
.to_string()
.as_str(),
16,
Alignment::Left,
None
))
)
.as_str(),
);
Expand Down Expand Up @@ -290,7 +320,7 @@ async fn redact_upload_file<
} else if redacter_base_options.allow_unsupported_copies {
bar.println(
format!(
"↳ Still copying {} because it is allowed by arguments",
"↳ Copying {} because it is explicitly allowed by arguments",
bold_style
.clone()
.yellow()
Expand Down
1 change: 0 additions & 1 deletion src/filesystems/aws_s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ impl<'a> FileSystemConnection<'a> for AwsS3FileSystem<'a> {
} else {
self.object_name.clone()
},
scheme: "s3".to_string(),
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/filesystems/gcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ impl<'a> FileSystemConnection<'a> for GoogleCloudStorageFileSystem<'a> {
} else {
self.object_name.clone()
},
scheme: "gcs".to_string(),
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/filesystems/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ impl<'a> FileSystemConnection<'a> for LocalFileSystem<'a> {
} else {
self.root_path.clone()
},
scheme: "file".to_string(),
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/filesystems/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ impl RelativeFilePath {
#[derive(Debug, Clone)]
pub struct AbsoluteFilePath {
pub file_path: String,
pub scheme: String,
}

#[derive(Debug, Clone)]
Expand Down
1 change: 0 additions & 1 deletion src/filesystems/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ impl<'a> FileSystemConnection<'a> for ZipFileSystem<'a> {
.map(|fr| format!(":{}", fr.relative_path.value()))
.unwrap_or("".to_string())
),
scheme: "zip".to_string(),
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/redacters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,11 @@ pub async fn redact_stream<
}),
}?;

for (redacter, options) in redacters_supported_options {
for (index, (redacter, options)) in redacters_supported_options.iter().enumerate() {
if !matches!(options, RedactSupportedOptions::Unsupported) {
let width = " ".repeat(index);
bar.println(format!(
"↳ Redacting using {} redacter",
"{width}↳ Redacting using {} redacter",
redacter.redacter_type()
));
item_to_redact = redacter.redact(item_to_redact).await?;
Expand Down

0 comments on commit 1b0e8ff

Please sign in to comment.