Skip to content

Commit 677140c

Browse files
Added CLI. See CHANGELOG.md for more details
1 parent 56cf519 commit 677140c

File tree

13 files changed

+447
-63
lines changed

13 files changed

+447
-63
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Changelog for Ferium
2+
3+
This changelog is formatted based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4+
5+
## [3.1.0] - 05.08.2021
6+
7+
### Added
8+
9+
- This changelog
10+
- Command line interface and corresponding code (under `cli.rs` and `cli.yaml`)
11+
- Help page and command, add mod command, list mods command
12+
- `Users` struct for Labrinth
13+
- JSON file write
14+
- `does_exist()` function for checking if a mod exists
15+
- Error codes (see changed)
16+
17+
### Changed
18+
19+
- Moved utilities to `util` folder
20+
- Made all panics into `println!`s and exits (with descriptive error codes)
21+
- Commented code better

Cargo.lock

Lines changed: 77 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
[package]
22
name = "ferium"
3-
version = "3.0.0"
3+
version = "3.1.0"
44
edition = "2018"
55
authors = ["theRookieCoder"]
66

77
[dependencies]
88
reqwest = { version = "0.11", features = ["json", "blocking"] }
99
serde = { version = "1", features = ["derive"] }
10+
clap = {version = "2", features = ["yaml"]}
1011
serde_json = "1"
1112
bytes = "1"
1213
shellexpand = "2"

LICENSE renamed to LICENSE.txt

File renamed without changes.

README.md

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,48 @@
11
# Ferium
22

3-
Ferium is a package manager like program for Minecraft mods (that are on Modrinth). You can add mods by finding your mods on Modrinth, specifying their project IDs in the config file, and running the command. Ferium will download the latest version of each mod in the config. It replaces (i.e. overwrites) any older downloads.
3+
Ferium is an open source and easy to use package manager for Minecraft mods (that are on [Modrinth](https://modrinth.com)).
44

5-
## Feature TODO
5+
## Feature to do
66

7-
- [ ] Check that the version is compatible with a specified Minecraft version
8-
- [ ] Allow configuration through a CLI
9-
- [ ] Release the Labrinth library as a seperate Crate
7+
- [x] Allow configuration through a CLI
108
- [ ] Add support for downloading from Github releases
9+
- [ ] Release the Labrinth library as a seperate Crate
10+
- [ ] Check that the version is compatible with a specified Minecraft version
1111
- [ ] Add support for downloading from CurseForge
12+
13+
## Help page
14+
15+
This section is the same as the one in `ferium help` + formatting.
16+
17+
### Usage
18+
`ferium <command> [arguments]`
19+
20+
### Commands
21+
- `list`
22+
- List all the mods configured with some of their metadata
23+
- `help`
24+
- Show this help page
25+
- `upgrade`
26+
- Download and install the latest version of the mods specified
27+
- `add MOD_ID`
28+
- Add a mod to the config
29+
- A mod's `MOD_ID` is specified as '`</>` PROJECT ID' in the right sidebar of the mod's Modrith page
30+
31+
### Examples
32+
```bash
33+
$ ferium upgrade # Upgrades all the mods in your config
34+
$ ferium add AANobbMI # Adds the Sodium mod to your config
35+
```
36+
37+
### Error codes
38+
- `120`: I/O error
39+
- `122`: JSON error
40+
- `124`: Server/HTTP error
41+
- `126`: General error
42+
43+
### Feedback
44+
You can [open an issue](https://github.com/theRookieCoder/ferium/issues/new).
45+
If you know how to and are willing to fix it, then you can make a pull request.
46+
47+
### Contributing
48+
Think you can improve Ferium? Well head on to [Ferium's repository](https://github.com/theRookieCoder/ferium) and you can start working on Ferium!

src/labrinth/funcs.rs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,58 @@
1+
/*
2+
* This file contains abstractions of some of the calls supported by the Labrinth API
3+
*/
4+
15
use super::structs::*;
26
use bytes::Bytes;
37
use reqwest::blocking::{get, Response};
8+
use reqwest::StatusCode;
9+
use std::process::exit;
410

511
/// Return the contents of `version`'s JAR file as bytes
612
pub fn download_version(version: &Version) -> Bytes {
713
match request(&version.files[0].url, false).bytes() {
814
Ok(contents) => contents,
9-
Err(e) => panic!("No response from server. {}", e),
15+
Err(e) => {
16+
println!("No response from server. {}", e);
17+
exit(124);
18+
}
19+
}
20+
}
21+
22+
// Chcek if a mod exists. If it does, then the mod is returned, else None is returned
23+
pub fn does_exist(mod_id: &ID) -> Option<Mod> {
24+
let response = request(&format!("/mod/{}", mod_id), true);
25+
match response.status() {
26+
StatusCode::OK => Some(match response.json() {
27+
Ok(typed) => typed,
28+
Err(e) => {
29+
println!("JSON deserialisation failed due to {}", e);
30+
exit(122);
31+
}
32+
}),
33+
_ => Option::None,
1034
}
1135
}
1236

1337
/// Returns the versions of `mod_id`'s mod sorted in chronologically descending order
1438
pub fn get_versions(mod_id: &str) -> Vec<Version> {
1539
match request(&format!("/mod/{}/version", mod_id), true).json() {
1640
Ok(typed) => typed,
17-
Err(e) => panic!("JSON deserialisation failed due to {}", e),
41+
Err(e) => {
42+
println!("JSON deserialisation failed due to {}", e);
43+
exit(122);
44+
}
1845
}
1946
}
2047

2148
/// Get a mod using the `mod_slug`, which can also be the mod ID
2249
pub fn get_mod(mod_slug: &str) -> Mod {
2350
match request(&format!("/mod/{}", mod_slug), true).json() {
2451
Ok(typed) => typed,
25-
Err(e) => panic!("JSON deserialisation failed due to {}", e),
52+
Err(e) => {
53+
println!("JSON deserialisation failed due to {}", e);
54+
exit(122);
55+
}
2656
}
2757
}
2858

@@ -40,9 +70,13 @@ fn request(url: &str, relative: bool) -> Response {
4070
if response.status().is_success() {
4171
response
4272
} else {
43-
panic!("HTTP request failed with error code {}", response.status());
73+
println!("HTTP request failed with error code {}", response.status());
74+
exit(124);
4475
}
4576
}
46-
Err(e) => panic!("HTTP request failed due to {}", e),
77+
Err(e) => {
78+
println!("HTTP request failed due to {}", e);
79+
exit(124);
80+
}
4781
}
4882
}

src/labrinth/structs.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*
2+
* This file contains typed structs of the data structures used by the Labrinth API
3+
*/
4+
15
use serde::{Deserialize, Serialize};
26
use std::collections::HashMap;
37
use std::vec::Vec;
@@ -31,6 +35,19 @@ pub struct VersionFile {
3135
pub filename: String,
3236
}
3337

38+
#[derive(Deserialize, Serialize, Debug)]
39+
pub struct User {
40+
pub id: ID,
41+
pub github_id: Option<u64>,
42+
pub username: String,
43+
pub name: String,
44+
pub email: Option<String>,
45+
pub avatar_url: Option<String>,
46+
pub bio: String,
47+
pub created: Datetime,
48+
pub role: String,
49+
}
50+
3451
#[derive(Deserialize, Serialize, Debug)]
3552
pub struct Mod {
3653
pub id: ID,

0 commit comments

Comments
 (0)