Skip to content

Commit b9d2126

Browse files
chore: pedantic clippy
1 parent 992531f commit b9d2126

17 files changed

+405
-281
lines changed

.gitmodules

Whitespace-only changes.

Cargo.lock

+298-207
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+30-11
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@ edition = "2021"
55
license = "MIT"
66
description = "A cli mod manager for the Northstar launcher"
77
readme = "README.md"
8-
authors = ["AnActualEmerald"]
8+
authors = [
9+
"AnActualEmerald",
10+
]
911
repository = "https://github.com/AnActualEmerald/papa"
10-
include = ["src/**/*", "LICENSE", "README.md", "CHANGELOG.*"]
12+
include = [
13+
"src/**/*",
14+
"LICENSE",
15+
"README.md",
16+
"CHANGELOG.*",
17+
]
1118

1219
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1320

1421
[dependencies]
1522
tracing = { default-features = false, version = "0.1.37" }
16-
libthermite = { git = "https://github.com/anactualemerald/thermite", branch = "main", version = "0.8.1", features = [
23+
libthermite = { git = "https://github.com/anactualemerald/thermite", branch = "dev", version = "0.8.1", features = [
1724
"steam",
1825
], default-features = false }
1926
anyhow = "1.0.72"
@@ -25,11 +32,15 @@ clap = { version = "4.3.19", features = [
2532
"usage",
2633
], default-features = false }
2734
directories = "5.0.1"
28-
regex = { version = "1.9.1", default-features = false, features = ["perf"] }
35+
regex = { version = "1.9.1", default-features = false, features = [
36+
"perf",
37+
] }
2938
serde = { version = "1.0.174", default-features = false }
3039
serde_json = { default-features = false, version = "1.0.103" }
31-
toml = { default-features = false, features = ["display"], version = "0.8" }
32-
zip = { default-features = false, version = "0.6.6" }
40+
toml = { default-features = false, features = [
41+
"display",
42+
], version = "0.8" }
43+
zip = { default-features = false, version = "2.2.0" }
3344
tracing-subscriber = { version = "0.3.17", features = [
3445
"ansi",
3546
"fmt",
@@ -61,11 +72,19 @@ source = "target/release/papa"
6172
dest = "/usr/bin/papa"
6273

6374
[features]
64-
default = ["northstar", "launcher"]
65-
northstar = []
66-
launcher = ["northstar"]
67-
cluster = []
68-
profiles = []
75+
default = [
76+
"northstar",
77+
"launcher",
78+
]
79+
northstar = [
80+
]
81+
launcher = [
82+
"northstar",
83+
]
84+
cluster = [
85+
]
86+
profiles = [
87+
]
6988

7089
[profile.release]
7190
strip = true

src/config.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ impl Config {
110110
pub fn remove_ignored(&mut self, val: impl AsRef<str>) -> bool {
111111
self.ignore.remove(val.as_ref())
112112
}
113+
114+
pub fn save(&self) -> Result<()> {
115+
let cereal = toml::to_string_pretty(self)?;
116+
fs::create_dir_all(DIRS.config_dir())?;
117+
fs::write(DIRS.config_dir().join("config.toml"), cereal)?;
118+
Ok(())
119+
}
113120
}
114121

115122
impl Default for Config {
@@ -151,10 +158,3 @@ impl Display for InstallType {
151158
write!(f, "{:?}", self)
152159
}
153160
}
154-
155-
pub fn write_config(cfg: &Config) -> Result<()> {
156-
let cereal = toml::to_string_pretty(cfg)?;
157-
fs::create_dir_all(DIRS.config_dir())?;
158-
fs::write(DIRS.config_dir().join("config.toml"), cereal)?;
159-
Ok(())
160-
}

src/core/commands/disable.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ use anyhow::Result;
44
use owo_colors::OwoColorize;
55
use thermite::{
66
model::{EnabledMods, InstalledMod},
7-
prelude::{find_mods, get_enabled_mods, ThermiteError},
7+
prelude::find_mods,
88
CORE_MODS,
99
};
1010
use tracing::debug;
1111

12-
use crate::{config::CONFIG, get_answer, model::ModName, traits::Answer};
12+
use crate::{config::CONFIG, get_answer, model::ModName, traits::Answer, utils::find_enabled_mods};
1313

1414
pub fn disable(mods: BTreeSet<String>, all: bool, force: bool) -> Result<()> {
1515
for m in mods.iter() {
@@ -45,7 +45,7 @@ pub fn disable(mods: BTreeSet<String>, all: bool, force: bool) -> Result<()> {
4545
}
4646
}
4747

48-
debug!("Checking if {} should be enabled", ModName::from(&v));
48+
debug!("Checking if {} should be disabled", ModName::from(&v));
4949
let res = mods.iter().find(|m| {
5050
if let Ok(mn) = TryInto::<ModName>::try_into(m.as_str()) {
5151
(mn.author.to_lowercase() == v.author.to_lowercase()
@@ -60,10 +60,9 @@ pub fn disable(mods: BTreeSet<String>, all: bool, force: bool) -> Result<()> {
6060
})
6161
.collect::<Vec<(String, InstalledMod)>>();
6262

63-
let mut enabled_mods = match get_enabled_mods(dir.join("..")) {
64-
Ok(mods) => mods,
65-
Err(ThermiteError::MissingFile(path)) => EnabledMods::default_with_path(*path),
66-
Err(e) => return Err(e.into()),
63+
let mut enabled_mods = match find_enabled_mods(&dir) {
64+
Some(mods) => mods,
65+
None => EnabledMods::default_with_path(dir.join("..").join("enabledmods.json")),
6766
};
6867

6968
debug!("Enabled mods: {:?}", enabled_mods.mods);

src/core/commands/enable.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use anyhow::Result;
44
use owo_colors::OwoColorize;
55
use tracing::debug;
66

7-
use crate::{config::CONFIG, model::ModName};
7+
use crate::{config::CONFIG, model::ModName, utils::find_enabled_mods};
88
use thermite::{
99
model::{EnabledMods, InstalledMod},
10-
prelude::{find_mods, get_enabled_mods, ThermiteError},
10+
prelude::find_mods,
1111
};
1212

1313
pub fn enable(mods: BTreeSet<String>, all: bool) -> Result<()> {
@@ -34,10 +34,9 @@ pub fn enable(mods: BTreeSet<String>, all: bool) -> Result<()> {
3434
})
3535
.collect::<Vec<(String, InstalledMod)>>();
3636

37-
let mut enabled_mods = match get_enabled_mods(dir.join("..")) {
38-
Ok(mods) => mods,
39-
Err(ThermiteError::MissingFile(path)) => EnabledMods::default_with_path(*path),
40-
Err(e) => return Err(e.into()),
37+
let mut enabled_mods = match find_enabled_mods(dir.join("..")) {
38+
Some(mods) => mods,
39+
None => EnabledMods::default_with_path(dir.join("..").join("enabledmods.json")),
4140
};
4241

4342
debug!("Enabled mods: {:?}", enabled_mods.mods);

src/core/commands/install.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use tracing::warn;
44

55
use crate::get_answer;
66
use crate::model::ModName;
7-
use crate::traits::{Answer, Index};
7+
use crate::traits::{Answer, Indexed};
88
use crate::utils::{download_and_install, to_file_size_string};
99

1010
use owo_colors::OwoColorize;

src/core/commands/list.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ use std::{
33
io::{ErrorKind, IsTerminal, Write},
44
};
55

6-
use anyhow::{Result};
6+
use anyhow::Result;
77
use owo_colors::OwoColorize;
88
use thermite::prelude::*;
99
use tracing::{debug, error, trace};
1010

11-
use crate::{config::CONFIG, model::ModName};
11+
use crate::{config::CONFIG, model::ModName, utils::find_enabled_mods};
1212

1313
pub fn list(global: bool, _all: bool) -> Result<()> {
1414
if global {
@@ -29,7 +29,7 @@ pub fn list(global: bool, _all: bool) -> Result<()> {
2929

3030
debug!("Found {} mods", mods.len());
3131
trace!("{:?}", mods);
32-
let enabled_mods = get_enabled_mods(CONFIG.install_dir()?.join("..")).ok();
32+
let enabled_mods = find_enabled_mods(CONFIG.install_dir()?);
3333

3434
let mut grouped_mods: BTreeMap<ModName, BTreeSet<String>> = BTreeMap::new();
3535
let mut disabled: BTreeMap<ModName, BTreeSet<String>> = BTreeMap::new();
@@ -80,6 +80,10 @@ pub fn list(global: bool, _all: bool) -> Result<()> {
8080
return Ok(());
8181
}
8282

83+
println!(
84+
"Current profile: {}",
85+
CONFIG.current_profile().bright_purple().bold()
86+
);
8387
println!("Installed mods: ");
8488
for (group, names) in grouped_mods {
8589
if names.len() == 1 {

src/core/commands/northstar.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ use std::path::{Path, PathBuf};
33
use std::time::Duration;
44

55
use crate::config::DIRS;
6-
use crate::traits::{Answer, Index};
6+
use crate::traits::{Answer, Indexed};
77
use crate::utils::init_msg;
8-
use crate::{
9-
config::{write_config, CONFIG},
10-
model::ModName,
11-
NstarCommands,
12-
};
8+
use crate::{config::CONFIG, model::ModName, NstarCommands};
139
use crate::{get_answer, modfile};
1410
use anyhow::{anyhow, Result};
1511
use indicatif::{ProgressBar, ProgressStyle};
@@ -58,7 +54,7 @@ fn init_ns(force: bool, path: Option<impl AsRef<Path>>) -> Result<()> {
5854
new_config.set_install_type(crate::config::InstallType::Steam);
5955
}
6056

61-
write_config(&new_config)?;
57+
new_config.save()?;
6258
return Ok(());
6359
}
6460

@@ -102,7 +98,7 @@ fn init_ns(force: bool, path: Option<impl AsRef<Path>>) -> Result<()> {
10298
if titanfall().is_some() {
10399
new_config.set_install_type(crate::config::InstallType::Steam);
104100
}
105-
write_config(&new_config)?;
101+
new_config.save()?;
106102

107103
Ok(())
108104
}

src/core/commands/profile.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn activate_profile(name: &String) -> Result<()> {
8484
println!(
8585
"Directory {} is on the ignore list. Please run '{}' and try again.",
8686
name.bright_red(),
87-
format!("papa profile unignore {}", name).bright_cyan()
87+
format!("papa profile unignore {name}").bright_cyan()
8888
);
8989
return Err(anyhow!("Profile was ignored"));
9090
}
@@ -200,7 +200,7 @@ fn clone_profile(source: &String, new: &Option<String>, force: bool) -> Result<(
200200
let target_dir = if let Some(target) = new {
201201
game.join(target)
202202
} else {
203-
game.join(format!("{}-copy", source))
203+
game.join(format!("{source}-copy"))
204204
};
205205
let target_name = target_dir
206206
.file_name()

src/core/commands/search.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::traits::Index;
1+
use crate::traits::Indexed;
22
use anyhow::Result;
33
use owo_colors::OwoColorize;
44
use textwrap::Options;

src/core/commands/update.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
core::commands::northstar,
66
get_answer,
77
model::ModName,
8-
traits::{Answer, Index},
8+
traits::{Answer, Indexed},
99
utils::{download_and_install, to_file_size_string},
1010
};
1111
use anyhow::Result;

src/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,6 @@ macro_rules! update_cfg {
9595
($($cmd:ident($op:tt)),*) => {{
9696
let mut c = $crate::config::CONFIG.clone();
9797
$(update_cfg!(@cmd c, $cmd $op);)*
98-
$crate::config::write_config(&c)
98+
c.save()
9999
}};
100100
}

src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ enum Commands {
7676
force: bool,
7777
},
7878

79-
///Install a mod or mods from https://northstar.thunderstore.io/
79+
///Install a mod or mods from <https://northstar.thunderstore.io/>
8080
#[clap(alias = "i")]
8181
Install {
8282
#[clap(value_name = "MOD", value_hint = ValueHint::Other)]

src/model.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl Display for ModName {
4444
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4545
write!(f, "{}.{}", self.author, self.name)?;
4646
if let Some(version) = &self.version {
47-
write!(f, "@{}", version)?;
47+
write!(f, "@{version}")?;
4848
}
4949

5050
Ok(())
@@ -138,7 +138,7 @@ impl Display for ModString {
138138
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
139139
write!(f, "{}-{}", self.author, self.inner.name)?;
140140
if let Some(version) = &self.version {
141-
write!(f, "-{}", version)?;
141+
write!(f, "-{version}")?;
142142
}
143143

144144
Ok(())
@@ -168,7 +168,7 @@ impl<'a> Display for ModStr<'a> {
168168
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
169169
write!(f, "{}-{}", self.author, self.inner.name)?;
170170
if let Some(version) = &self.version {
171-
write!(f, "-{}", version)?;
171+
write!(f, "-{version}")?;
172172
}
173173

174174
Ok(())

src/traits.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ use tracing::debug;
55

66
use crate::model::ModName;
77

8-
const SCORE_THRESHOLD: i32 = 75;
8+
const SCORE_THRESHOLD: i64 = 75;
99

1010
pub trait Answer {
1111
fn is_no(&self) -> bool;
1212
fn is_yes(&self) -> bool;
1313
}
1414

15-
pub trait Index<T> {
15+
pub trait Indexed<T> {
1616
fn get_item(&self, name: &ModName) -> Option<&T>;
1717
fn search(&self, term: &str) -> Vec<&T>;
1818
}
1919

20-
impl Index<Mod> for Vec<Mod> {
20+
impl Indexed<Mod> for Vec<Mod> {
2121
fn get_item(&self, name: &ModName) -> Option<&Mod> {
2222
self.iter().find(|v| {
2323
v.name.to_lowercase() == name.name.to_lowercase()
@@ -31,24 +31,24 @@ impl Index<Mod> for Vec<Mod> {
3131
}
3232
let matcher = SkimMatcherV2::default();
3333
let mut res = vec![];
34-
for v in self.iter() {
34+
for v in self {
3535
let author = matcher.fuzzy_indices(&v.author, term);
3636
let name = matcher.fuzzy_indices(&v.name, term);
3737
let desc = matcher.fuzzy_indices(&v.get_latest().unwrap().desc, term);
3838

3939
if let Some((score, _)) = author {
4040
debug!("author matched with score '{score}'");
41-
if score >= SCORE_THRESHOLD as i64 {
41+
if score >= SCORE_THRESHOLD {
4242
res.push((score, v));
4343
}
4444
} else if let Some((score, _)) = name {
4545
debug!("name matched with score '{score}'");
46-
if score >= SCORE_THRESHOLD as i64 {
46+
if score >= SCORE_THRESHOLD {
4747
res.push((score, v));
4848
}
4949
} else if let Some((score, _)) = desc {
5050
debug!("desc matched with score '{score}'");
51-
if score >= SCORE_THRESHOLD as i64 {
51+
if score >= SCORE_THRESHOLD {
5252
res.push((score, v));
5353
}
5454
}
@@ -59,7 +59,7 @@ impl Index<Mod> for Vec<Mod> {
5959
}
6060
}
6161

62-
impl Index<InstalledMod> for Vec<InstalledMod> {
62+
impl Indexed<InstalledMod> for Vec<InstalledMod> {
6363
fn get_item(&self, name: &ModName) -> Option<&InstalledMod> {
6464
self.iter()
6565
.find(|v| v.mod_json.name.to_lowercase() == name.name.to_lowercase())

0 commit comments

Comments
 (0)