// xxx ssh keys: need a force option to set key for non ssh: account
// xxx make default account be ssh:<user>: rather than unix:<user>: if we are passed --ssh
-// xxx make remote otter have a different error message prefix
use otter::imports::*;
#[throws(AE)]
fn call(SCCA{ out, ma, args,.. }:SCCA) {
+ set_program_name("otter (remote)".into());
+
let args = parse_args::<Args,_>(args, &subargs, &ok_id, None);
let mut chan = connect_chan(&ma)?;
}
impl Default for PathResolveContext { fn default() -> Self { Self::Noop } }
+static PROGRAM_NAME: RwLock<String> = parking_lot::const_rwlock(String::new());
+
impl PathResolveMethod {
#[throws(io::Error)]
fn chdir(self, cd: &str) -> PathResolveContext {
spec.resolve(default()).expect("empty spec into config")
}
}
+
+pub fn set_program_name(s: String) {
+ *PROGRAM_NAME.write() = s;
+}
+
+pub fn program_name() -> String {
+ {
+ let set = PROGRAM_NAME.read();
+ if set.len() > 0 { return set.clone() }
+ }
+
+ let mut w = PROGRAM_NAME.write();
+ if w.len() > 0 { return w.clone() }
+
+ let new = env::args().next().expect("expected at least 0 arguments");
+ let new = match new.rsplit_once('/') {
+ Some((_path,leaf)) => leaf.to_owned(),
+ None => new,
+ };
+ let new = if new.len() > 0 { new } else { "otter".to_owned() };
+ *w = new.clone();
+ new
+}
fn d(&self) -> AnyhowDisplay<'_> { AnyhowDisplay(self) }
fn end_process(self, estatus: u8) -> ! {
- #[derive(Default,Debug)] struct Sol { any: bool }
+ #[derive(Default,Debug)] struct Sol { any: bool, progname: String }
impl Sol {
fn nl(&mut self) {
if self.any { eprintln!("") };
self.any = false;
}
fn head(&mut self) {
- if ! self.any { eprint!("otter: error"); }
+ if ! self.any { eprint!("{}: error", &self.progname); }
self.any = true
}
}
- let mut sol: Sol = default();
+ let mut sol: Sol = Sol { any: false, progname: program_name() };
self.for_each(&mut |s|{
let long = s.len() > 80;
if long && sol.any { sol.nl() }