Skip to content

Commit c8aec72

Browse files
committed
now much more better
1 parent 48d946a commit c8aec72

File tree

16 files changed

+203
-160
lines changed

16 files changed

+203
-160
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ exclude = ["images/"]
1616
clap = { version = "4.5", features = ["derive"] }
1717
colored = "3.0"
1818
inquire = "0.7"
19-
reqwest = { version = "0.12", features = ["blocking", "json"] }
19+
reqwest = { version = "0.12", features = ["json"] }
2020
tokio = { version = "1.0", features = ["full"] }
2121
serde = { version = "1.0", features = ["derive"] }
2222
serde_json = "1.0"
23+
anyhow = "1.0"
2324

2425
[lints.rust]
25-
dead_code = "allow"
26+
dead_code = "allow"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ Note: The `--mc-version` and `--eula` flags are only required for Java Edition s
5252
```bash
5353
mcsast setup --software=paper --mc-version=1.21.1 --eula=true -y
5454
```
55-
### Update to latest build of current Minecraft version
55+
### Sync latest build of current Minecraft version
5656
```bash
57-
mcsast update
57+
mcsast sync
5858
```
5959
### Upgrade Minecraft version
6060
```bash

src/cli/commands/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
pub mod setup;
2-
pub mod update;
2+
pub mod sync;
33
pub mod upgrade;
44
pub mod plugins;
55

66
pub use setup::handle_setup;
7-
pub use update::handle_update;
7+
pub use sync::handle_sync;
88
pub use upgrade::handle_upgrade;
99
pub use plugins::handle_plugins;

src/cli/commands/plugins.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
use anyhow::Result;
12
use crate::cli::PluginActions;
23
use crate::plugins;
34

4-
pub async fn handle_plugins(action: PluginActions) -> Result<(), Box<dyn std::error::Error>> {
5+
pub async fn handle_plugins(action: PluginActions) -> Result<()> {
56
match action {
67
PluginActions::List => plugins::list_plugins().await,
78
PluginActions::Add { name, force } => plugins::get_plugin(&name, force).await,

src/cli/commands/setup.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
use std::{io::Write, process::exit};
22
use colored::Colorize;
33
use inquire::{Confirm, Select, Text};
4+
use anyhow::Result;
45

56
use crate::core::{Config, Software, eula};
67
use crate::download;
78
use crate::utils::{get_current_directory_name, get_executable_extension, inquired, print_error_and_exit};
89

9-
pub fn handle_setup(
10+
pub async fn handle_setup(
1011
software: Option<Software>,
1112
mc_version: Option<String>,
1213
eula: Option<bool>,
1314
yes: bool,
14-
) -> Result<(), Box<dyn std::error::Error>> {
15+
) -> Result<()> {
1516
let software = {
1617
if software.is_none() {
1718
let binding = Select::new(
@@ -136,7 +137,7 @@ pub fn handle_setup(
136137
);
137138
std::io::stdout().flush()?;
138139

139-
match download::get(software.name(), version.clone()) {
140+
match download::get(&software.name(), version.clone()).await {
140141
Err(e) => {
141142
println!();
142143
println!("{}: {}", "error".bold().red(), e);
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
use std::{io::Write, process::exit};
22
use colored::Colorize;
3+
use anyhow::Result;
34

45
use crate::core::Config;
56
use crate::download;
67
use crate::utils::get_executable_extension;
78

8-
pub fn handle_update() -> Result<(), Box<dyn std::error::Error>> {
9+
pub async fn handle_sync() -> Result<()> {
910
let config = Config::load()?;
1011

1112
if !config.software.supports_minecraft_version() {
1213
println!(
13-
"🔄 Updating {} to latest build...",
14+
"🔄 Syncing {} to latest build...",
1415
config.software.name().bold().yellow()
1516
);
1617
} else {
1718
println!(
18-
"🔄 Updating {}-{} to latest build...",
19+
"🔄 Syncing {}-{} to latest build...",
1920
config.software.name().bold().yellow(),
2021
config.minecraft_version.bold().blue()
2122
);
@@ -27,7 +28,7 @@ pub fn handle_update() -> Result<(), Box<dyn std::error::Error>> {
2728
);
2829
std::io::stdout().flush()?;
2930

30-
match download::get(config.software.name(), config.minecraft_version.clone()) {
31+
match download::get(&config.software.name(), config.minecraft_version.clone()).await {
3132
Err(e) => {
3233
println!();
3334
println!("{}: {}", "error".bold().red(), e);
@@ -43,14 +44,14 @@ pub fn handle_update() -> Result<(), Box<dyn std::error::Error>> {
4344
println!(
4445
" {} server.jar {}",
4546
"↻".green().bold(),
46-
"(updated to latest build)".dimmed()
47+
"(synced to latest build)".dimmed()
4748
);
4849
} else {
4950
println!(
5051
" {} gate{} {}",
5152
"↻".green().bold(),
5253
need_exe,
53-
"(updated to latest build)".dimmed()
54+
"(synced to latest build)".dimmed()
5455
);
5556
}
5657

src/cli/commands/upgrade.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use std::{io::Write, process::exit};
22
use colored::Colorize;
33
use inquire::Text;
4+
use anyhow::Result;
45

56
use crate::core::Config;
67
use crate::download;
78
use crate::utils::{inquired, print_error_and_exit};
89

9-
pub fn handle_upgrade(target_version: Option<String>) -> Result<(), Box<dyn std::error::Error>> {
10+
pub async fn handle_upgrade(target_version: Option<String>) -> Result<()> {
1011
let mut config = Config::load()?;
1112

1213
let target_version = {
@@ -16,7 +17,7 @@ pub fn handle_upgrade(target_version: Option<String>) -> Result<(), Box<dyn std:
1617
"❌ {} upgrades are currently unsupported.",
1718
config.software.name()
1819
);
19-
return Err(not_supported_message.into());
20+
return Err(anyhow::anyhow!("{}", not_supported_message));
2021
} else {
2122
let binding =
2223
Text::new("🚀 What version of Minecraft would you like to upgrade to?")
@@ -43,7 +44,7 @@ pub fn handle_upgrade(target_version: Option<String>) -> Result<(), Box<dyn std:
4344
);
4445
std::io::stdout().flush()?;
4546

46-
match download::get(config.software.name(), target_version.clone()) {
47+
match download::get(&config.software.name(), target_version.clone()).await {
4748
Err(e) => {
4849
println!();
4950
println!("{}: {}", "error".bold().red(), e);

src/cli/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ pub enum Commands {
3232
#[arg(short, default_value_t = false)]
3333
yes: bool,
3434
},
35-
/// update to latest build of this version
36-
Update,
35+
/// sync to latest build of this version
36+
Sync,
3737
/// upgrade to another version
3838
Upgrade {
3939
/// your target minecraft version

src/core/config.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::core::software::Software;
22
use serde::{Deserialize, Serialize};
33
use std::{fs, path::Path};
4+
use anyhow::Result;
45

56
const CONFIG_FILE: &str = "mcsast.config.json";
67

@@ -24,17 +25,17 @@ pub struct Config {
2425
}
2526

2627
impl Config {
27-
pub fn load() -> Result<Self, Box<dyn std::error::Error>> {
28+
pub fn load() -> Result<Self> {
2829
if !Path::new(CONFIG_FILE).exists() {
29-
return Err("No config file found. Please run 'mcsast setup' first.".into());
30+
return Err(anyhow::anyhow!("No config file found. Please run 'mcsast setup' first."));
3031
}
3132

3233
let content = fs::read_to_string(CONFIG_FILE)?;
3334
let config: Config = serde_json::from_str(&content)?;
3435
Ok(config)
3536
}
3637

37-
pub fn save(&self) -> Result<(), Box<dyn std::error::Error>> {
38+
pub fn save(&self) -> Result<()> {
3839
let content = serde_json::to_string_pretty(self)?;
3940
fs::write(CONFIG_FILE, content)?;
4041
Ok(())

0 commit comments

Comments
 (0)