44 lines
1.5 KiB
Rust
44 lines
1.5 KiB
Rust
use rhai::{Array, Engine};
|
|
use crate::{api::models::{OrderServerProduct, AuctionServerProduct, AuctionTransaction, ServerAddonProduct, ServerAddonTransaction, Server, SshKey}};
|
|
|
|
mod servers_table;
|
|
mod ssh_keys_table;
|
|
mod server_ordering_table;
|
|
|
|
// This will be called when we print(...) or pretty_print() an Array (with Dynamic values)
|
|
pub fn pretty_print_dispatch(array: Array) {
|
|
if array.is_empty() {
|
|
println!("<empty table>");
|
|
return;
|
|
}
|
|
|
|
let first = &array[0];
|
|
|
|
if first.is::<Server>() {
|
|
println!("Yeah first is server!");
|
|
servers_table::pretty_print_servers(array);
|
|
} else if first.is::<SshKey>() {
|
|
ssh_keys_table::pretty_print_ssh_keys(array);
|
|
}
|
|
else if first.is::<OrderServerProduct>() {
|
|
server_ordering_table::pretty_print_server_products(array);
|
|
} else if first.is::<AuctionServerProduct>() {
|
|
server_ordering_table::pretty_print_auction_server_products(array);
|
|
} else if first.is::<AuctionTransaction>() {
|
|
server_ordering_table::pretty_print_auction_transactions(array);
|
|
} else if first.is::<ServerAddonProduct>() {
|
|
server_ordering_table::pretty_print_server_addon_products(array);
|
|
} else if first.is::<ServerAddonTransaction>() {
|
|
server_ordering_table::pretty_print_server_addon_transactions(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);
|
|
}
|