errors now print to stderr instead of stdout

This commit is contained in:
Valerie Wolfe 2024-07-12 10:48:03 -04:00
parent cdc68986fa
commit b7b893d55c

View file

@ -2,7 +2,7 @@ use std::process::exit;
/// no subcommand that matches user input; code 1 /// no subcommand that matches user input; code 1
pub fn no_subcommand(subcommand: String) { pub fn no_subcommand(subcommand: String) {
println!("remux: no command match for \"{subcommand}\""); eprintln!("remux: no command match for \"{subcommand}\"");
exit(1); exit(1);
} }
@ -10,68 +10,68 @@ pub fn no_subcommand(subcommand: String) {
/// target session not found; code 2 /// target session not found; code 2
pub fn no_target<S: Into<String>>(target: S) { pub fn no_target<S: Into<String>>(target: S) {
let target = target.into(); let target = target.into();
println!("remux: no session \"{target}\" exists"); eprintln!("remux: no session \"{target}\" exists");
exit(2); exit(2);
} }
/// help topic doesn't exist; code 3 /// help topic doesn't exist; code 3
pub fn no_help(topic: String) { pub fn no_help(topic: String) {
println!("remux: no help for \"{topic}\""); eprintln!("remux: no help for \"{topic}\"");
exit(3); exit(3);
} }
/// user provided no target; code 4 /// user provided no target; code 4
pub fn missing_target() { pub fn missing_target() {
println!("remux: no target provided"); eprintln!("remux: no target provided");
exit(4); exit(4);
} }
/// refuse to attach to current session; code 4 /// refuse to attach to current session; code 4
pub fn same_session() { pub fn same_session() {
println!("remux: cannot attach to same session"); eprintln!("remux: cannot attach to same session");
exit(4); exit(4);
} }
/// a session with the target name already exists; code 4 /// a session with the target name already exists; code 4
pub fn target_exists<S: Into<String>>(target: S) { pub fn target_exists<S: Into<String>>(target: S) {
let target = target.into(); let target = target.into();
println!("remux: session \"{target}\" already exists"); eprintln!("remux: session \"{target}\" already exists");
exit(4); exit(4);
} }
/// non-terminal environment prevention; code 5 /// non-terminal environment prevention; code 5
pub fn not_terminal() { pub fn not_terminal() {
println!("remux: not running from a terminal"); eprintln!("remux: not running from a terminal");
exit(5); exit(5);
} }
/// tried to nest while not in a session; code 6 /// tried to nest while not in a session; code 6
pub fn not_nesting() { pub fn not_nesting() {
println!("remux: inappropriate nesting flag (-n); not in a session"); eprintln!("remux: inappropriate nesting flag (-n); not in a session");
exit(6); exit(6);
} }
/// operation requires nesting flag; code 6 /// operation requires nesting flag; code 6
pub fn prevent_nest() { pub fn prevent_nest() {
println!("remux: the nesting flag (-n) is required for nesting operation"); eprintln!("remux: the nesting flag (-n) is required for nesting operation");
exit(6); exit(6);
} }
/// operation conflicts with nesting flag; code 6 /// operation conflicts with nesting flag; code 6
pub fn conflict_nest(reason: Option<&'static str>) { pub fn conflict_nest(reason: Option<&'static str>) {
if let Some(reason) = reason { println!("remux: inappropriate nesting flag (-n): {reason}"); } if let Some(reason) = reason { eprintln!("remux: inappropriate nesting flag (-n): {reason}"); }
else { println!("remux: nesting flag (-n) is inappropriate for this operation."); } else { eprintln!("remux: nesting flag (-n) is inappropriate for this operation."); }
exit(6); exit(6);
} }
/// tried to run a session command outside a session; code 7 /// tried to run a session command outside a session; code 7
pub fn not_in_session(cmd: &'static str) { pub fn not_in_session(cmd: &'static str) {
println!("remux: '{cmd}' must be run from within a session"); eprintln!("remux: '{cmd}' must be run from within a session");
exit(7); exit(7);
} }