Forgive me if my english seems a bit wrong, english is not my first language
Anyway, I'm writing something that requires me to make command-line arguments,
and was stuck with this very tacky and tedious solution:
fn installer_args<'a, I>(&self, install_dir: I, game_version: String) -> Vec<Cow<'a, str>>
where
I: AsRef<Path> + 'a,
{
match self {
Self::Forge => vec![
Cow::from("--installServer"),
Cow::from(install_dir.as_ref().to_string_lossy().to_string()),
],
Self::Neoforge => vec![
Cow::from("--installServer"),
Cow::from(install_dir.as_ref().to_string_lossy().to_string()),
],
Self::Quilt => vec![
Cow::from("install"),
Cow::from("server"),
Cow::from(game_version),
Cow::from(format!(
"--install-dir={}",
install_dir.as_ref().to_string_lossy()
)),
Cow::from("--create-scripts"),
Cow::from("--download-server"),
],
Self::Fabric => vec![
Cow::from("server"),
Cow::from("-dir"),
Cow::from(install_dir.as_ref().to_string_lossy().to_string()),
Cow::from("-mcversion"),
Cow::from(game_version),
Cow::from("-downloadMinecraft"),
],
Self::Glowstone => todo!(), // TODO: Also this
}
}
I really dont like it, and I only require these arguments to be passable in Command::args
.
I originally thought of using Vec<A>
, where A: ToString
to no avail
Is it possible to make my code better?