Skip to content

Commit

Permalink
Show full source path if relative path is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Systemcluster committed Nov 21, 2023
1 parent 2c0b09b commit 17865d4
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,34 +118,29 @@ fn main() {
std::process::exit(-1);
});

let canonical_current_dir = std::fs::canonicalize(std::env::current_dir().unwrap()).unwrap();
let relative_source = source
.strip_prefix(&canonical_current_dir)
.unwrap_or(&source);
let relative_source = if relative_source.components().count() == 0 {
&canonical_current_dir
} else {
relative_source
};
let count = if source.is_dir() {
println!(
"{} {}counting contents of {}…",
style("[1/4]").bold().dim(),
Emoji("🔍 ", ""),
style(
&source
.strip_prefix(std::fs::canonicalize(std::env::current_dir().unwrap()).unwrap())
.unwrap_or(&source)
.display()
)
.blue()
.bright()
style(relative_source.display()).blue().bright()
);
WalkDir::new(&source).skip_hidden(false).into_iter().count() as u64 - 1
} else {
println!(
"{} {}checking {}…",
style("[1/4]").bold().dim(),
Emoji("🔍 ", ""),
style(
&source
.strip_prefix(std::fs::canonicalize(std::env::current_dir().unwrap()).unwrap())
.unwrap_or(&source)
.display()
)
.blue()
.bright()
style(relative_source.display()).blue().bright()
);
1
};
Expand All @@ -156,7 +151,7 @@ fn main() {
Emoji("📃 ", ""),
style(
&output
.strip_prefix(std::fs::canonicalize(std::env::current_dir().unwrap()).unwrap())
.strip_prefix(&canonical_current_dir)
.unwrap_or(&output)
.display()
)
Expand All @@ -177,7 +172,7 @@ fn main() {
.unwrap_or_else(|error| {
println!(
" {}{} {}",
Emoji("⚠️ ", ""),
Emoji(" ", ""),
style("failed to set subsystem for runner:").yellow(),
style(error).yellow()
);
Expand Down Expand Up @@ -206,7 +201,7 @@ fn main() {
.unwrap_or_else(|error| {
println!(
" {}{} {}",
Emoji("⚠️ ", ""),
Emoji(" ", ""),
style("failed to copy resources to runner:").yellow(),
style(error).yellow()
);
Expand Down Expand Up @@ -242,7 +237,11 @@ fn main() {
},
|message| {
bar_progress.inc(1);
bar_progress.println(format!(" {}{}", Emoji("⚠️ ", ""), style(message).red()));
bar_progress.println(format!(
" {}{}",
Emoji("❗ ", ""),
style(message).red()
));
},
|message| {
bar_progress.set_message(format!("{}", style(message).blue().bright()));
Expand Down Expand Up @@ -314,7 +313,7 @@ fn main() {
set_permissions(&output, PermissionsExt::from_mode(mode | 0o111)).unwrap_or_else(|e| {
eprintln!(
" {} failed to set permissions for {}: {}",
Emoji("⚠️ ", ""),
Emoji(" ", ""),
output.display(),
e
)
Expand Down

0 comments on commit 17865d4

Please sign in to comment.