-
-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathmain.rs
More file actions
116 lines (103 loc) · 2.41 KB
/
Copy pathmain.rs
File metadata and controls
116 lines (103 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
use clap::Parser;
use dotenv::dotenv;
use log::debug;
use commands::configure::Configuration;
use crate::commands::configure::Modifiers;
use crate::executable::handle_exit_status;
use crate::logger::debug_mode;
use crate::messages::about;
use crate::utils::is_root::is_root;
mod cli;
pub mod commands;
mod constants;
mod errors;
mod executable;
mod files;
mod logger;
mod messages;
mod mods;
mod notifications;
pub mod server;
mod steamcmd;
pub mod traits;
pub mod utils;
fn main() {
if is_root() {
panic!("You must run this executable without root permissions");
}
dotenv().ok();
use cli::{Cli, Commands};
let cli = Cli::parse();
logger::initialize_logger(cli.debug || debug_mode()).unwrap();
if cli.debug {
debug!("Debug mode enabled!");
}
match cli.commands {
Commands::Configure {
name,
public,
password,
server_executable,
world,
port,
modifiers,
preset,
set_key,
save_interval,
} => Configuration::new(
name,
server_executable,
port,
world,
password,
{ public.eq("1") }.to_owned(),
preset,
{
modifiers.map(|modifiers| {
modifiers
.split(',')
.map(|modifier| Modifiers::from(modifier.to_string()))
.collect()
})
},
set_key,
save_interval,
)
.invoke(),
Commands::Install {} => handle_exit_status(
commands::install::invoke(constants::GAME_ID),
"Successfully installed Valheim!".to_string(),
),
Commands::Start {} => commands::start::invoke(cli.dry_run),
Commands::Stop {} => commands::stop::invoke(cli.dry_run),
Commands::Backup {
input_directory,
output_file,
} => commands::backup::invoke(input_directory, output_file),
Commands::Update { check, force } => commands::update::invoke(cli.dry_run, check, force),
Commands::Notify {
title,
message,
webhook_url,
} => commands::notify::invoke(title, message, webhook_url),
Commands::ModInstall { url } => commands::install_mod::invoke(url),
Commands::Status {
json,
local,
address,
} => commands::status::invoke(json, local, address),
Commands::About {} => {
about(env!("GIT_HASH"));
}
}
}
#[cfg(test)]
mod tests {
// use super::*;
use clap::CommandFactory;
use crate::cli::Cli;
#[test]
fn asserts() {
Cli::command().debug_assert();
}
}