Skip to content

Commit

Permalink
fix: print to stderr when appropriate
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Mar 6, 2024
1 parent 093dec0 commit ce8206f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion edu-sync-cli/src/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Subcommand {
.insert(account_config.id.to_string(), account_config);
config.write().await?;

println!("Successfully added {}", account_name);
eprintln!("Successfully added {}", account_name);

Ok(())
}
Expand Down
28 changes: 14 additions & 14 deletions edu-sync-cli/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct Syncer {

impl Syncer {
async fn from(config: Config) -> Self {
println!("Requesting content databases...");
eprintln!("Requesting content databases...");
let parallel_downloads = config.parallel_downloads;
let outdated_courses = config
.accounts
Expand Down Expand Up @@ -91,7 +91,7 @@ impl Syncer {
})
})
.collect::<FuturesOrdered<_>>()
.filter_map(|res| future::ready(res.map_err(|err| println!("{}", err)).ok()))
.filter_map(|res| future::ready(res.map_err(|err| eprintln!("{}", err)).ok()))
.filter(|course_status| future::ready(!course_status.downloads.is_empty()))
.collect::<Vec<_>>()
.await;
Expand All @@ -103,9 +103,9 @@ impl Syncer {

async fn sync(self, no_confirm: bool) -> anyhow::Result<()> {
if self.outdated_courses.is_empty() {
println!("All resources are up to date.");
eprintln!("All resources are up to date.");
} else {
println!();
eprintln!();

let size_width = 9;
let pad_course_name = |course_name| {
Expand All @@ -131,7 +131,7 @@ impl Syncer {
(count, size, name)
})
.inspect(|(count, size, name)| {
println!(
eprintln!(
"{} {:>4} items, totalling {}",
pad_course_name(name),
count,
Expand All @@ -148,9 +148,9 @@ impl Syncer {
Cow::from("N/A")
};

println!();
println!("Total: {} items, totalling {}", count, size);
println!();
eprintln!();
eprintln!("Total: {} items, totalling {}", count, size);
eprintln!();

let proceed = no_confirm
|| task::spawn_blocking(|| {
Expand All @@ -162,7 +162,7 @@ impl Syncer {
.await??;

if proceed {
println!("Downloading missing files...");
eprintln!("Downloading missing files...");
self.download().await?;
}
}
Expand Down Expand Up @@ -231,8 +231,8 @@ impl Syncer {

let (file_downloads, content_downloads, size_progress, content_progress, size) =
download_tasks
.filter_map(|res| future::ready(res.map_err(|err| println!("{}", err)).ok()))
.filter_map(|res| future::ready(res.map_err(|err| println!("{}", err)).ok()))
.filter_map(|res| future::ready(res.map_err(|err| eprintln!("{}", err)).ok()))
.filter_map(|res| future::ready(res.map_err(|err| eprintln!("{}", err)).ok()))
.fold(
(Vec::new(), Vec::new(), Vec::new(), Vec::new(), 0),
|(
Expand Down Expand Up @@ -339,22 +339,22 @@ impl CourseStatus {
None
}
SyncStatus::Outdated(path) => {
println!("Outdated: {}", path.display());
eprintln!("Outdated: {}", path.display());
None
}
SyncStatus::UpToDate(path) => {
trace!("Up to date: {}", path.display());
None
}
SyncStatus::Modified(path) => {
println!("Modified: {}", path.display());
eprintln!("Modified: {}", path.display());
None
}
}
})
})
.collect::<FuturesUnordered<_>>()
.filter_map(|res| future::ready(res.map_err(|err| println!("{}", err)).ok()))
.filter_map(|res| future::ready(res.map_err(|err| eprintln!("{}", err)).ok()))
.collect::<Vec<_>>()
.await
.into_iter()
Expand Down
6 changes: 3 additions & 3 deletions edu-sync-cli/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use edu_sync::config::Config;
pub fn check_accounts(config: &Config) -> bool {
let sucess = config.has_accounts();
if !sucess {
println!("No accounts configured. To add an account, use the add subcommand.");
eprintln!("No accounts configured. To add an account, use the add subcommand.");
}
sucess
}
Expand All @@ -12,10 +12,10 @@ pub fn check_active_courses(config: &Config) -> bool {
if !check_accounts(config) {
false
} else if !config.has_courses() {
println!("No courses known. To fetch available courses, use the fetch subcommand.");
eprintln!("No courses known. To fetch available courses, use the fetch subcommand.");
false
} else if !config.has_active_courses() {
println!(
eprintln!(
"No courses activated. To activate synchronization for courses, edit the config at {}",
Config::path().display()
);
Expand Down

0 comments on commit ce8206f

Please sign in to comment.