use nu_plugin::{Plugin, PluginCommand};
mod commands;
mod security;
mod ulid_engine;
use commands::*;
pub use security::*;
pub use ulid_engine::*;
pub struct UlidPlugin;
impl Plugin for UlidPlugin {
fn version(&self) -> String {
env!("CARGO_PKG_VERSION").into()
}
fn commands(&self) -> Vec<Box<dyn PluginCommand<Plugin = Self>>> {
vec![
Box::new(UlidGenerateCommand),
Box::new(UlidValidateCommand),
Box::new(UlidParseCommand),
Box::new(UlidInspectCommand),
Box::new(UlidSortCommand),
Box::new(UlidSecurityAdviceCommand),
Box::new(UlidInfoCommand),
Box::new(UlidTimeNowCommand),
Box::new(UlidTimeParseCommand),
Box::new(UlidTimeMillisCommand),
Box::new(UlidEncodeBase32Command),
Box::new(UlidDecodeBase32Command),
Box::new(UlidEncodeHexCommand),
Box::new(UlidDecodeHexCommand),
Box::new(UlidToBytesCommand),
]
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_plugin_version() {
let plugin = UlidPlugin;
assert!(!plugin.version().is_empty());
}
#[test]
fn test_plugin_commands() {
let plugin = UlidPlugin;
let commands = plugin.commands();
assert_eq!(commands.len(), 15);
let command_names: Vec<&str> = commands.iter().map(|cmd| cmd.name()).collect();
assert!(command_names.contains(&"ulid generate"));
assert!(command_names.contains(&"ulid validate"));
assert!(command_names.contains(&"ulid parse"));
assert!(command_names.contains(&"ulid inspect"));
assert!(command_names.contains(&"ulid sort"));
assert!(command_names.contains(&"ulid security-advice"));
assert!(command_names.contains(&"ulid info"));
assert!(command_names.contains(&"ulid time now"));
assert!(command_names.contains(&"ulid encode base32"));
}
}