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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
use std::path::PathBuf;
use clap::{Parser, Subcommand};
use tracing::debug;
use tracing_subscriber::{EnvFilter, FmtSubscriber};
pub mod config;
mod core;
pub mod model;
pub mod traits;
pub mod utils;
#[macro_use]
mod macros;
use model::ModName;
use utils::validate_modname;
#[derive(Parser)]
#[clap(name = "Papa")]
#[clap(author = "AnAcutalEmerald <emerald_actual@proton.me>")]
#[clap(about = "Command line mod manager for Northstar")]
#[clap(after_help = "Welcome back. Cockpit cooling reactivated.")]
#[clap(version)]
struct Cli {
#[clap(subcommand)]
command: Commands,
///Show debug output
#[clap(global = true, short, long)]
debug: bool,
///Don't check cache before downloading
#[clap(global = true, short = 'C', long = "no-cache")]
no_cache: bool,
}
#[derive(Subcommand)]
enum Commands {
///Show the current config and environment info
Env {},
///Export the list of currently installed mods
Export {
#[clap(default_value = "papa.ron")]
file: PathBuf,
},
///Import a list of mods, installing them to the current install directory
Import {
///'papa.ron' file to import
#[arg(default_value = "papa.ron")]
file: PathBuf,
///Don't ask for confirmation
#[clap(short, long)]
yes: bool,
///Force installation
#[clap(short, long)]
force: bool,
},
///Install a mod or mods from https://northstar.thunderstore.io/
#[clap(alias = "i")]
Install {
#[clap(value_name = "MOD")]
#[clap(help = "Mod name(s) to install")]
#[clap(required_unless_present = "file")]
#[clap(value_parser = validate_modname)]
mod_names: Vec<ModName>,
///File to read the list of mods from
#[arg(short = 'F', long)]
file: Option<PathBuf>,
///Don't ask for confirmation
#[clap(short, long)]
yes: bool,
///Force installation
#[clap(short, long)]
force: bool,
///Make mod globally available (currently non-functioning)
#[clap(short, long)]
global: bool,
},
///Remove a mod or mods from the current mods directory
#[clap(alias = "r", alias = "rm")]
Remove {
#[clap(value_name = "MOD")]
#[clap(help = "Mod name(s) to remove")]
#[clap(value_parser = validate_modname)]
#[clap(required = true)]
mod_names: Vec<ModName>,
},
///List installed mods
#[clap(alias = "l", alias = "ls")]
List {
///List only globally installed mods
#[clap(short, long)]
global: bool,
///List both local and global mods
#[clap(short, long)]
all: bool,
},
///Update currently installed mods
#[clap(alias = "u")]
Update {
///Don't ask for confirmation
#[clap(short, long)]
yes: bool,
},
///Search for a mod
#[clap(alias = "s")]
Search {
///The term to search for
term: Vec<String>,
},
///Disable mod(s) or sub-mod(s)
Disable {
mods: Vec<String>,
///Disable all mods excluding core N* mods
#[clap(short, long)]
all: bool,
///Force disable mods including core N* mods
#[clap(short, long)]
force: bool,
},
///Enable mod(s) or sub-mod(s)
Enable {
mods: Vec<String>,
#[arg(short, long)]
all: bool,
},
///Commands for managing Northstar itself
#[cfg(feature = "northstar")]
#[clap(alias("ns"))]
Northstar {
#[clap(subcommand)]
command: NstarCommands,
},
}
#[derive(Subcommand)]
pub enum NstarCommands {
///Attempts to install Northstar to a Titanfall 2 Steam installation, or updates the configuration if it already exists.
Init {
/// Ignore non-fatal errors
#[arg(default_value_t = false, short, long)]
force: bool,
/// The path to install Northstar into. Defaults to the local Titanfall 2 steam installation, if available.
path: Option<PathBuf>,
},
///Updates the current northstar install.
Update {},
// #[cfg(feature = "launcher")]
// ///Start the Northstar client
// Start {},
}
fn main() {
let cli = Cli::parse();
if cli.debug {
std::env::set_var("RUST_LOG", "DEBUG");
}
let subscriber = FmtSubscriber::builder()
.with_env_filter(EnvFilter::from_default_env())
.finish();
tracing::subscriber::set_global_default(subscriber).expect("Unable to init tracing");
debug!("Config: {:#?}", *config::CONFIG);
let res = match cli.command {
Commands::Update { yes } => core::update(yes, cli.no_cache),
Commands::List { global, all } => core::list(global, all),
Commands::Install {
file, yes, force, ..
} if file.is_some() => {
let Some(f) = file else {
return
};
core::import(f, yes, force, cli.no_cache)
}
Commands::Install {
mod_names,
yes,
force,
..
} => core::install(mod_names, yes, force, cli.no_cache),
Commands::Disable { mods, all, force } => {
core::disable(mods.into_iter().collect(), all, force)
}
Commands::Enable { mods, all } => core::enable(mods.into_iter().collect(), all),
Commands::Search { term } => core::search(&term),
Commands::Remove { mod_names } => core::remove(mod_names),
Commands::Import { file, yes, force } => core::import(file, yes, force, cli.no_cache),
Commands::Export { file } => core::export(file),
Commands::Env {} => core::env(),
// Commands::Clear { full } => clear(&ctx, full),
#[cfg(feature = "northstar")]
Commands::Northstar { command } => core::northstar(&command),
};
if let Err(e) = res {
if cli.debug {
debug!("{:#?}", e);
}
}
}