switch from thiserror to color-eyre
This commit is contained in:
parent
82d085b11e
commit
cfb8eac3f9
|
@ -21,4 +21,5 @@ shulkerscript-lang = {path = "../shulkerscript-lang", features = ["shulkerbox"],
|
||||||
shulkerbox = {path = "../shulkerbox", default-features = false}
|
shulkerbox = {path = "../shulkerbox", default-features = false}
|
||||||
git2 = { version = "0.18.3", default-features = false }
|
git2 = { version = "0.18.3", default-features = false }
|
||||||
path-absolutize = "3.1.1"
|
path-absolutize = "3.1.1"
|
||||||
|
color-eyre = "0.6.3"
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
use crate::{
|
use crate::subcommands::{self, BuildArgs, InitArgs};
|
||||||
error::Result,
|
|
||||||
subcommands::{self, BuildArgs, InitArgs},
|
|
||||||
};
|
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
use color_eyre::eyre::Result;
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
|
|
10
src/error.rs
10
src/error.rs
|
@ -2,12 +2,6 @@ use std::path::PathBuf;
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("An error occurred while parsing command-line arguments.")]
|
|
||||||
IoError(#[from] std::io::Error),
|
|
||||||
#[error("An error occured while serializing to TOML.")]
|
|
||||||
TomlSerializeError(#[from] toml::ser::Error),
|
|
||||||
#[error("An error occured while deserializing from TOML.")]
|
|
||||||
TomlDeserializeError(#[from] toml::de::Error),
|
|
||||||
#[error("No file/directory found at path {0}.")]
|
#[error("No file/directory found at path {0}.")]
|
||||||
PathNotFoundError(PathBuf),
|
PathNotFoundError(PathBuf),
|
||||||
#[error("An error occured because the directory {0} is not empty.")]
|
#[error("An error occured because the directory {0} is not empty.")]
|
||||||
|
@ -16,10 +10,6 @@ pub enum Error {
|
||||||
NotDirectoryError(PathBuf),
|
NotDirectoryError(PathBuf),
|
||||||
#[error("An error occured because the path is neither a pack directory or a pack.toml file.")]
|
#[error("An error occured because the path is neither a pack directory or a pack.toml file.")]
|
||||||
InvalidPackPathError(PathBuf),
|
InvalidPackPathError(PathBuf),
|
||||||
#[error("An error occured while compiling the project.")]
|
|
||||||
ShulkerScriptError(#[from] shulkerscript_lang::base::Error),
|
|
||||||
#[error("An error occured during a git action.")]
|
|
||||||
GitError(#[from] git2::Error),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Error>;
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -1,13 +1,12 @@
|
||||||
use std::process::ExitCode;
|
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use color_eyre::eyre::Result;
|
||||||
use shulkerscript::cli::Args;
|
use shulkerscript::cli::Args;
|
||||||
|
|
||||||
fn main() -> ExitCode {
|
fn main() -> Result<()> {
|
||||||
|
color_eyre::install()?;
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
match args.run() {
|
args.run()?;
|
||||||
Ok(_) => ExitCode::SUCCESS,
|
|
||||||
Err(_) => ExitCode::FAILURE,
|
Ok(())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
|
use color_eyre::eyre::Result;
|
||||||
use path_absolutize::Absolutize;
|
use path_absolutize::Absolutize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::ProjectConfig,
|
config::ProjectConfig,
|
||||||
error::{Error, Result},
|
error::Error,
|
||||||
terminal_output::{print_error, print_info},
|
terminal_output::{print_error, print_info},
|
||||||
};
|
};
|
||||||
use std::{fs, path::PathBuf};
|
use std::{fs, path::PathBuf};
|
||||||
|
@ -24,12 +25,12 @@ pub fn build(_verbose: bool, args: &BuildArgs) -> Result<()> {
|
||||||
|
|
||||||
let toml_path = if !path.exists() {
|
let toml_path = if !path.exists() {
|
||||||
print_error("The specified path does not exist.");
|
print_error("The specified path does not exist.");
|
||||||
return Err(Error::PathNotFoundError(path.to_path_buf()));
|
return Err(Error::PathNotFoundError(path.to_path_buf()))?;
|
||||||
} else if path.is_dir() {
|
} else if path.is_dir() {
|
||||||
let toml_path = path.join("pack.toml");
|
let toml_path = path.join("pack.toml");
|
||||||
if !toml_path.exists() {
|
if !toml_path.exists() {
|
||||||
print_error("The specified directory does not contain a pack.toml file.");
|
print_error("The specified directory does not contain a pack.toml file.");
|
||||||
return Err(Error::InvalidPackPathError(path.to_path_buf()));
|
Err(Error::InvalidPackPathError(path.to_path_buf()))?;
|
||||||
}
|
}
|
||||||
toml_path
|
toml_path
|
||||||
} else if path.is_file()
|
} else if path.is_file()
|
||||||
|
@ -41,7 +42,7 @@ pub fn build(_verbose: bool, args: &BuildArgs) -> Result<()> {
|
||||||
path.to_path_buf()
|
path.to_path_buf()
|
||||||
} else {
|
} else {
|
||||||
print_error("The specified path is neither a directory nor a pack.toml file.");
|
print_error("The specified path is neither a directory nor a pack.toml file.");
|
||||||
return Err(Error::InvalidPackPathError(path.to_path_buf()));
|
return Err(Error::InvalidPackPathError(path.to_path_buf()))?;
|
||||||
};
|
};
|
||||||
|
|
||||||
let toml_content = fs::read_to_string(&toml_path)?;
|
let toml_content = fs::read_to_string(&toml_path)?;
|
||||||
|
|
|
@ -4,6 +4,7 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use clap::ValueEnum;
|
use clap::ValueEnum;
|
||||||
|
use color_eyre::eyre::Result;
|
||||||
use git2::{
|
use git2::{
|
||||||
IndexAddOption as GitIndexAddOption, Repository as GitRepository, Signature as GitSignature,
|
IndexAddOption as GitIndexAddOption, Repository as GitRepository, Signature as GitSignature,
|
||||||
};
|
};
|
||||||
|
@ -11,7 +12,7 @@ use path_absolutize::Absolutize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::ProjectConfig,
|
config::ProjectConfig,
|
||||||
error::{Error, Result},
|
error::Error,
|
||||||
terminal_output::{print_error, print_info, print_success},
|
terminal_output::{print_error, print_info, print_success},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -52,13 +53,13 @@ pub fn init(verbose: bool, args: &InitArgs) -> Result<()> {
|
||||||
|
|
||||||
if !path.exists() {
|
if !path.exists() {
|
||||||
print_error("The specified path does not exist.");
|
print_error("The specified path does not exist.");
|
||||||
Err(Error::PathNotFoundError(path.to_path_buf()))
|
Err(Error::PathNotFoundError(path.to_path_buf()))?
|
||||||
} else if !path.is_dir() {
|
} else if !path.is_dir() {
|
||||||
print_error("The specified path is not a directory.");
|
print_error("The specified path is not a directory.");
|
||||||
Err(Error::NotDirectoryError(path.to_path_buf()))
|
Err(Error::NotDirectoryError(path.to_path_buf()))?
|
||||||
} else if !force && path.read_dir()?.next().is_some() {
|
} else if !force && path.read_dir()?.next().is_some() {
|
||||||
print_error("The specified directory is not empty.");
|
print_error("The specified directory is not empty.");
|
||||||
Err(Error::NonEmptyDirectoryError(path.to_path_buf()))
|
Err(Error::NonEmptyDirectoryError(path.to_path_buf()))?
|
||||||
} else {
|
} else {
|
||||||
let name = args
|
let name = args
|
||||||
.name
|
.name
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use clap::ValueEnum;
|
use clap::ValueEnum;
|
||||||
|
|
||||||
use crate::error::Result;
|
use color_eyre::eyre::Result;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[derive(Debug, clap::Args, Clone)]
|
#[derive(Debug, clap::Args, Clone)]
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
|
use color_eyre::eyre::Result;
|
||||||
use path_absolutize::Absolutize;
|
use path_absolutize::Absolutize;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::ProjectConfig,
|
config::ProjectConfig,
|
||||||
error::{Error, Result},
|
error::Error,
|
||||||
terminal_output::{print_error, print_info},
|
terminal_output::{print_error, print_info},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,12 +27,12 @@ pub fn package(_verbose: bool, args: &PackageArgs) -> Result<()> {
|
||||||
|
|
||||||
let toml_path = if !path.exists() {
|
let toml_path = if !path.exists() {
|
||||||
print_error("The specified path does not exist.");
|
print_error("The specified path does not exist.");
|
||||||
return Err(Error::PathNotFoundError(path.to_path_buf()));
|
return Err(Error::PathNotFoundError(path.to_path_buf()))?;
|
||||||
} else if path.is_dir() {
|
} else if path.is_dir() {
|
||||||
let toml_path = path.join("pack.toml");
|
let toml_path = path.join("pack.toml");
|
||||||
if !toml_path.exists() {
|
if !toml_path.exists() {
|
||||||
print_error("The specified directory does not contain a pack.toml file.");
|
print_error("The specified directory does not contain a pack.toml file.");
|
||||||
return Err(Error::InvalidPackPathError(path.to_path_buf()));
|
Err(Error::InvalidPackPathError(path.to_path_buf()))?;
|
||||||
}
|
}
|
||||||
toml_path
|
toml_path
|
||||||
} else if path.is_file()
|
} else if path.is_file()
|
||||||
|
@ -43,7 +44,7 @@ pub fn package(_verbose: bool, args: &PackageArgs) -> Result<()> {
|
||||||
path.to_path_buf()
|
path.to_path_buf()
|
||||||
} else {
|
} else {
|
||||||
print_error("The specified path is neither a directory nor a pack.toml file.");
|
print_error("The specified path is neither a directory nor a pack.toml file.");
|
||||||
return Err(Error::InvalidPackPathError(path.to_path_buf()));
|
return Err(Error::InvalidPackPathError(path.to_path_buf()))?;
|
||||||
};
|
};
|
||||||
|
|
||||||
let toml_content = fs::read_to_string(&toml_path)?;
|
let toml_content = fs::read_to_string(&toml_path)?;
|
||||||
|
|
Loading…
Reference in New Issue