Add path-absolutize crate and use it in build.rs and init.rs

This commit is contained in:
Moritz Hölting 2024-04-09 11:40:51 +02:00
parent 0432c8466e
commit 742d128030
3 changed files with 15 additions and 11 deletions

View File

@ -20,4 +20,5 @@ toml = "0.8.12"
shulkerscript-lang = {path = "../shulkerscript-lang", features = ["shulkerbox"], default-features = false}
shulkerbox = {path = "../shulkerbox", default-features = false}
git2 = { version = "0.18.3", default-features = false }
path-absolutize = "3.1.1"

View File

@ -1,3 +1,5 @@
use path_absolutize::Absolutize;
use crate::{
config::ProjectConfig,
error::{Error, Result},
@ -5,8 +7,6 @@ use crate::{
};
use std::{fs, path::PathBuf};
use crate::util;
#[derive(Debug, clap::Args, Clone)]
pub struct BuildArgs {
/// The path of the project to build.
@ -17,8 +17,10 @@ pub struct BuildArgs {
pub fn build(_verbose: bool, args: &BuildArgs) -> Result<()> {
let path = args.path.as_path();
let str_path = util::to_absolute_path(path)?;
print_info(&format!("Building project at {}", str_path));
print_info(&format!(
"Building project at {}",
path.absolutize()?.display()
));
let toml_path = if !path.exists() {
print_error("The specified path does not exist.");
@ -61,7 +63,7 @@ pub fn build(_verbose: bool, args: &BuildArgs) -> Result<()> {
print_info(&format!(
"Finished building project to {}",
util::to_absolute_path(&dist_path)?
dist_path.absolutize_from(path)?.display()
));
Ok(())

View File

@ -7,12 +7,12 @@ use clap::ValueEnum;
use git2::{
IndexAddOption as GitIndexAddOption, Repository as GitRepository, Signature as GitSignature,
};
use path_absolutize::Absolutize;
use crate::{
config::ProjectConfig,
error::{Error, Result},
terminal_output::{print_error, print_info, print_success},
util::to_absolute_path,
};
#[derive(Debug, clap::Args, Clone)]
@ -32,6 +32,7 @@ pub struct InitArgs {
/// Force initialization even if the directory is not empty.
#[clap(short, long)]
force: bool,
/// The version control system to initialize.
#[clap(long, default_value = "git")]
vcs: VersionControlSystem,
}
@ -118,7 +119,7 @@ fn create_pack_config(
if verbose {
print_info(&format!(
"Created pack.toml file at {}.",
to_absolute_path(&path)?
path.absolutize()?.display()
));
}
Ok(())
@ -130,7 +131,7 @@ fn create_dir(path: &Path, verbose: bool) -> std::io::Result<()> {
if verbose {
print_info(&format!(
"Created directory at {}.",
to_absolute_path(path)?
path.absolutize()?.display()
));
}
}
@ -143,7 +144,7 @@ fn create_gitignore(path: &Path, verbose: bool) -> std::io::Result<()> {
if verbose {
print_info(&format!(
"Created .gitignore file at {}.",
to_absolute_path(&gitignore)?
gitignore.absolutize()?.display()
));
}
Ok(())
@ -155,7 +156,7 @@ fn create_pack_png(path: &Path, verbose: bool) -> std::io::Result<()> {
if verbose {
print_info(&format!(
"Created pack.png file at {}.",
to_absolute_path(&pack_png)?
pack_png.absolutize()?.display()
));
}
Ok(())
@ -173,7 +174,7 @@ fn create_main_file(path: &Path, namespace: &str, verbose: bool) -> std::io::Res
if verbose {
print_info(&format!(
"Created main.shu file at {}.",
to_absolute_path(&main_file)?
main_file.absolutize()?.display()
));
}
Ok(())