elemental_core/launcher/
command.rs1use std::{collections::HashMap, path::PathBuf};
2
3use crate::runtime::distribution::Distribution;
4
5#[derive(Debug, Clone)]
6pub struct LaunchCommand {
7 pub runtime: Distribution,
8 pub jvm_arguments: Vec<String>,
9 pub main_class: String,
10 pub game_arguments: Vec<String>,
11 pub env: HashMap<String, String>,
12 pub cwd: Option<PathBuf>,
13}
14
15impl LaunchCommand {
16 pub fn new(
17 runtime: Distribution,
18 jvm_arguments: Vec<String>,
19 main_class: String,
20 game_arguments: Vec<String>,
21 ) -> Self {
22 Self {
23 runtime,
24 jvm_arguments,
25 main_class,
26 game_arguments,
27 env: HashMap::new(),
28 cwd: None,
29 }
30 }
31
32 pub fn program(&self) -> PathBuf {
33 self.runtime.executable()
34 }
35
36 pub fn arguments(&self) -> Vec<String> {
37 let mut arguments = self.jvm_arguments.clone();
38 arguments.push(self.main_class.clone());
39 arguments.extend(self.game_arguments.clone());
40 arguments
41 }
42
43 pub fn add_jvm_argument(&mut self, argument: String) {
44 self.jvm_arguments.push(argument);
45 }
46
47 pub fn add_jvm_arguments(&mut self, arguments: Vec<String>) {
48 self.jvm_arguments.extend(arguments);
49 }
50
51 pub fn add_game_argument(&mut self, argument: String) {
52 self.game_arguments.push(argument);
53 }
54
55 pub fn add_game_arguments(&mut self, arguments: Vec<String>) {
56 self.game_arguments.extend(arguments);
57 }
58
59 pub fn with_cwd(mut self, cwd: PathBuf) -> Self {
60 self.cwd = Some(cwd);
61 self
62 }
63
64 pub fn with_env(mut self, key: String, value: String) -> Self {
65 self.env.insert(key, value);
66 self
67 }
68}