Skip to content

Commit ab032de

Browse files
committed
even more clippy warnings
1 parent 94f2b07 commit ab032de

File tree

3 files changed

+2
-160
lines changed

3 files changed

+2
-160
lines changed

src/indexer.rs

+1-151
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,9 @@
11
use crate::config::geode_root;
2-
use crate::util::logging::ask_value;
32
use std::fs;
43
use std::path::PathBuf;
5-
use git2::{Repository, ResetType, IndexAddOption, Signature};
6-
use crate::package::mod_json_from_archive;
7-
use crate::{info, done, fatal, warn, NiceUnwrap};
4+
use crate::fatal;
85
use colored::Colorize;
96

10-
fn reset_and_commit(repo: &Repository, msg: &str) {
11-
let head = repo.head().nice_unwrap("Broken repository, can't get HEAD");
12-
if !head.is_branch() {
13-
fatal!("Broken repository, detached HEAD");
14-
}
15-
16-
let mut commit = head.peel_to_commit().unwrap();
17-
while commit.parent_count() > 0 {
18-
commit = commit.parent(0).unwrap();
19-
}
20-
21-
repo.reset(commit.as_object(), ResetType::Soft, None).nice_unwrap("Unable to refresh repository");
22-
23-
let mut index = repo.index().nice_unwrap("cannot get the Index file");
24-
index.add_all(["."].iter(), IndexAddOption::DEFAULT, None).nice_unwrap("Unable to add changes");
25-
index.write().nice_unwrap("Unable to write changes");
26-
27-
let sig = Signature::now("GeodeBot", "[email protected]").unwrap();
28-
29-
let tree = repo.find_tree(index.write_tree().nice_unwrap("Unable to get write tree")).unwrap();
30-
repo.commit(Some("HEAD"), &sig, &sig, msg, &tree, &[&commit]).nice_unwrap("Unable to commit");
31-
}
32-
337
pub fn indexer_path() -> PathBuf {
348
geode_root().join("indexer")
359
}
@@ -38,31 +12,6 @@ pub fn is_initialized() -> bool {
3812
indexer_path().exists()
3913
}
4014

41-
pub fn initialize() {
42-
if is_initialized() {
43-
done!("Indexer is already initialized");
44-
return;
45-
}
46-
47-
info!(
48-
"Before publishing mods on the Geode index, we need to make you a local \
49-
Indexer, which handles everything related to publishing mods."
50-
);
51-
info!(
52-
"The mod binaries will be hosted on your Indexer repository, which will \
53-
automatically request them to be added to the official Mods Index."
54-
);
55-
info!(
56-
"To get started, log in to Github using your account, and go to \
57-
https://github.com/geode-sdk/indexer/fork to make a fork of the Indexer."
58-
);
59-
60-
let fork_url = ask_value("Enter the URL of your fork", None, true);
61-
Repository::clone(&fork_url, indexer_path()).nice_unwrap("Unable to clone your repository.");
62-
63-
done!("Successfully initialized Indexer");
64-
}
65-
6615
pub fn list_mods() {
6716
if !is_initialized() {
6817
fatal!("Indexer has not been set up - use `geode indexer init` to set it up");
@@ -78,102 +27,3 @@ pub fn list_mods() {
7827
}
7928
}
8029
}
81-
82-
pub fn remove_mod(id: String) {
83-
if !is_initialized() {
84-
fatal!("Indexer has not been set up - use `geode indexer init` to set it up");
85-
}
86-
let indexer_path = indexer_path();
87-
88-
let mod_path = indexer_path.join(&id);
89-
if !mod_path.exists() {
90-
fatal!("Cannot remove mod {}: does not exist", id);
91-
}
92-
93-
fs::remove_dir_all(mod_path).nice_unwrap("Unable to remove mod");
94-
95-
let repo = Repository::open(&indexer_path).nice_unwrap("Unable to open repository");
96-
reset_and_commit(&repo, &format!("Remove {}", &id));
97-
98-
done!("Succesfully removed {}\n", id);
99-
info!("You will need to force-push to sync your changes.");
100-
info!("Run `git -C {} push -f` to sync your changes", indexer_path.to_str().unwrap());
101-
}
102-
103-
pub fn add_mod(package: PathBuf) {
104-
if !is_initialized() {
105-
fatal!("Indexer has not been set up - use `geode indexer init` to set it up");
106-
}
107-
let indexer_path = indexer_path();
108-
109-
if !package.exists() {
110-
fatal!("Package path {} does not exist!", package.display());
111-
}
112-
113-
let mut archive = zip::ZipArchive::new(fs::File::open(&package).unwrap()).nice_unwrap("Unable to read package");
114-
115-
let mod_json = mod_json_from_archive(&mut archive);
116-
117-
let major_version = mod_json
118-
.get("version")
119-
.nice_unwrap("[mod.json]: Missing key 'version'")
120-
.as_str()
121-
.nice_unwrap("[mod.json].version: Expected string")
122-
.split('.')
123-
.next()
124-
.unwrap()
125-
.chars()
126-
.filter(|x| *x != 'v')
127-
.collect::<String>();
128-
129-
let mod_id = mod_json_from_archive(&mut archive)
130-
.get("id")
131-
.nice_unwrap("[mod.json]: Missing key 'id'")
132-
.as_str()
133-
.nice_unwrap("[mod.json].id: Expected string")
134-
.to_string();
135-
136-
let mod_path = indexer_path.join(format!("{}@{}", &mod_id, &major_version));
137-
if !mod_path.exists() {
138-
fs::create_dir(&mod_path)
139-
.nice_unwrap("Unable to create directory in local indexer for mod");
140-
}
141-
142-
fs::copy(package, mod_path.join("mod.geode"))
143-
.nice_unwrap("Unable to copy .geode package to local Indexer");
144-
145-
let repo = Repository::open(&indexer_path)
146-
.nice_unwrap("Unable to open local Indexer repository");
147-
reset_and_commit(&repo, &format!("Add/Update {}", &mod_id));
148-
149-
match repo.find_remote("origin").and_then(|mut o| o.push(&["main"], None)) {
150-
Ok(_) => {
151-
done!(
152-
"Succesfully added {}@{} to your indexer!",
153-
mod_id, major_version
154-
);
155-
},
156-
Err(_) => {
157-
done!("Successfully added {}@{}\n", mod_id, major_version);
158-
warn!(
159-
"Unable to automatically sync the changes to Github. \
160-
You will need to push this commit yourself."
161-
);
162-
info!("Run `git -C {} push -f` to push the commit", indexer_path.to_str().unwrap());
163-
},
164-
}
165-
if let Some(url) = repo.find_remote("origin").unwrap().url() {
166-
info!(
167-
"To let us know you're ready to publish your mod, please open \
168-
a Pull Request on your repository: \
169-
{}/compare/geode-sdk:indexer:main...main",
170-
url
171-
);
172-
}
173-
else {
174-
info!(
175-
"To let us know you're ready to publish your mod, please open \
176-
a Pull Request on your Indexer fork repository."
177-
);
178-
};
179-
}

src/project.rs

-8
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,6 @@ fn find_build_directory(root: &Path) -> Option<PathBuf> {
7171
}
7272
}
7373

74-
/// Get the project's built .geode file. Path argument should point to the
75-
/// directory with the project's mod.json
76-
pub fn get_built_package(root: &Path) -> Option<PathBuf> {
77-
let mod_info = try_parse_mod_info(root).ok()?;
78-
let geode_pkg = find_build_directory(root)?.join(format!("{}.geode", mod_info.id));
79-
geode_pkg.exists().then_some(geode_pkg)
80-
}
81-
8274
fn clear_cache(dir: &Path) {
8375
// Parse mod.json
8476
let mod_info = parse_mod_info(dir);

src/template.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn create_template(
8888

8989
// Write formatted json
9090
fs::write(
91-
&project_location.join("mod.json"),
91+
project_location.join("mod.json"),
9292
String::from_utf8(ser.into_inner()).unwrap(),
9393
).nice_unwrap("Unable to write to project");
9494

0 commit comments

Comments
 (0)