use clap::{CommandFactory, Parser};
use serde::Serialize;
mod serializer;
use serializer::to_args;
pub trait FmtArgs {
fn to_args(&self) -> Vec<String>;
fn to_args_with_program(&self, program: &str) -> Vec<String>;
}
impl<T> FmtArgs for T
where
T: Parser + CommandFactory + Serialize,
{
fn to_args(&self) -> Vec<String> {
let cmd = Self::command();
to_args(self, &cmd).unwrap_or_else(|e| {
panic!("Failed to convert to args: {e}");
})
}
fn to_args_with_program(&self, program: &str) -> Vec<String> {
let mut result = vec![program.to_string()];
result.extend(self.to_args());
result
}
}