31 lines
731 B
Rust
31 lines
731 B
Rust
use rhai::{Array, Engine};
|
|
use crate::scripting::{Server, SshKey};
|
|
|
|
mod servers_table;
|
|
mod ssh_keys_table;
|
|
|
|
pub fn pretty_print_dispatch(array: Array) {
|
|
println!("pretty print dispatch");
|
|
if array.is_empty() {
|
|
println!("<empty table>");
|
|
return;
|
|
}
|
|
|
|
let first = &array[0];
|
|
|
|
if first.is::<Server>() {
|
|
servers_table::pretty_print_servers(array);
|
|
} else if first.is::<SshKey>() {
|
|
ssh_keys_table::pretty_print_ssh_keys(array);
|
|
} else {
|
|
// Generic fallback for other types
|
|
for item in array {
|
|
println!("{}", item.to_string());
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn register(engine: &mut Engine) {
|
|
engine.register_fn("pretty_print", pretty_print_dispatch);
|
|
}
|