63 lines
3.5 KiB
Rust
63 lines
3.5 KiB
Rust
//! Prints the events of one liblore operation, for checking what liblore reports.
|
|
//!
|
|
//! LORE_FORGE_LIBLORE=<liblore> cargo run -p lore-sys --example probe -- <op> <working copy> [arg]
|
|
//!
|
|
//! Operations: status, scan, branches, history, info <rev>, diff <from> <to>, locks, files <path>,
|
|
//! repos <remote>, users <id>, logins, clone <url>, sync, login <remote>, stage <path>,
|
|
//! commit <message>, push, lock <path> [branch], unlock <path> [branch] [owner id],
|
|
//! lockstatus <path> [branch], watch (notifications until killed), watchfor <seconds>
|
|
//! (subscribes, then unsubscribes from another thread).
|
|
|
|
use lore_sys::Globals;
|
|
use lore_sys::Lore;
|
|
|
|
fn main() {
|
|
let lib = std::env::var_os("LORE_FORGE_LIBLORE").expect("set LORE_FORGE_LIBLORE");
|
|
let lore = Lore::load(std::path::Path::new(&lib)).unwrap();
|
|
let args: Vec<String> = std::env::args().skip(1).collect();
|
|
let op = args.first().map(String::as_str).unwrap_or("status");
|
|
let globals = Globals { repository_path: args.get(1).cloned().unwrap_or_default(), ..Globals::default() };
|
|
let a = args.get(2).cloned().unwrap_or_default();
|
|
let b = args.get(3).cloned().unwrap_or_default();
|
|
let c = args.get(4).cloned().unwrap_or_default();
|
|
let print = |event| println!("{event:?}");
|
|
let result = match op {
|
|
"status" => lore.repository_status(&globals, false, print),
|
|
"scan" => lore.repository_status(&globals, true, print),
|
|
"branches" => lore.branch_list(&globals, print),
|
|
"history" => lore.revision_history(&globals, &a, "", 20, print),
|
|
"info" => lore.revision_info(&globals, &a, true, true, print),
|
|
"diff" => lore.revision_diff(&globals, &a, &b, print),
|
|
"locks" => lore.lock_file_query(&globals, &a, print),
|
|
"files" => lore.file_history(&globals, &a, 20, print),
|
|
"repos" => lore.repository_list(&globals, &a, print),
|
|
"users" => lore.auth_user_info(&globals, std::slice::from_ref(&a), print),
|
|
"logins" => lore.auth_list(&globals, print),
|
|
"clone" => lore.repository_clone(&globals, &a, print),
|
|
"sync" => lore.revision_sync(&globals, print),
|
|
"stage" => lore.file_stage(&globals, std::slice::from_ref(&a), print),
|
|
"commit" => lore.revision_commit(&globals, &a, print),
|
|
"push" => lore.branch_push(&globals, print),
|
|
"lock" => lore.lock_file_acquire(&globals, std::slice::from_ref(&a), &b, print),
|
|
"unlock" => lore.lock_file_release(&globals, std::slice::from_ref(&a), &b, "", &c, print),
|
|
"lockstatus" => lore.lock_file_status(&globals, std::slice::from_ref(&a), &b, print),
|
|
"watch" => lore.notification_subscribe(&globals, |event| {
|
|
println!("{event:?}");
|
|
use std::io::Write;
|
|
std::io::stdout().flush().unwrap();
|
|
}),
|
|
"watchfor" => std::thread::scope(|scope| {
|
|
let watcher = scope.spawn(|| lore.notification_subscribe(&globals, |event| println!("watch: {event:?}")));
|
|
std::thread::sleep(std::time::Duration::from_secs(a.parse().unwrap()));
|
|
println!("unsubscribe: {:?}", lore.notification_unsubscribe(&globals, print));
|
|
let started = std::time::Instant::now();
|
|
let ended = watcher.join().unwrap();
|
|
println!("subscribe ended after {:?}: {ended:?}", started.elapsed());
|
|
Ok(())
|
|
}),
|
|
"login" => lore.auth_login_interactive(&globals, &a, true, print),
|
|
other => panic!("unknown operation {other}"),
|
|
};
|
|
println!("=> {result:?}");
|
|
}
|