use super::global::GlobalOptions;
use super::types::Command;
#[derive(Debug, Clone)]
pub struct ParsedCommand {
pub command: Command,
pub global: GlobalOptions,
pub from_legacy: bool,
pub legacy_invocation: Option<String>,
pub suggested_invocation: Option<String>,
}
impl ParsedCommand {
pub fn new(command: Command, global: GlobalOptions) -> Self {
Self {
command,
global,
from_legacy: false,
legacy_invocation: None,
suggested_invocation: None,
}
}
pub fn from_legacy(
command: Command,
global: GlobalOptions,
legacy_invocation: String,
suggested_invocation: String,
) -> Self {
Self {
command,
global,
from_legacy: true,
legacy_invocation: Some(legacy_invocation),
suggested_invocation: Some(suggested_invocation),
}
}
pub fn emit_deprecation_warning(&self) {
if self.from_legacy
&& !self.global.quiet
&& let (Some(old), Some(new)) = (&self.legacy_invocation, &self.suggested_invocation)
{
eprintln!(
"[loct][deprecated] '{}' -> '{}'. This alias will be removed in v1.0.",
old, new
);
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::cli::command::options::DeadOptions;
#[test]
fn test_parsed_command_deprecation_warning() {
let cmd = ParsedCommand::from_legacy(
Command::Dead(DeadOptions::default()),
GlobalOptions::default(),
"loct -A --dead".to_string(),
"loct dead".to_string(),
);
assert!(cmd.from_legacy);
assert_eq!(cmd.legacy_invocation, Some("loct -A --dead".to_string()));
}
}