add clean subcommand to CLI
This commit is contained in:
parent
cfb8eac3f9
commit
ebb8fff3d3
|
@ -1,4 +1,4 @@
|
||||||
use crate::subcommands::{self, BuildArgs, InitArgs};
|
use crate::subcommands::{self, BuildArgs, CleanArgs, InitArgs};
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
|
|
||||||
|
@ -18,6 +18,9 @@ pub enum Command {
|
||||||
Init(InitArgs),
|
Init(InitArgs),
|
||||||
/// Build the project.
|
/// Build the project.
|
||||||
Build(BuildArgs),
|
Build(BuildArgs),
|
||||||
|
/// Clean build artifacts.
|
||||||
|
/// This will remove the `dist` directory.
|
||||||
|
Clean(CleanArgs),
|
||||||
#[cfg(feature = "zip")]
|
#[cfg(feature = "zip")]
|
||||||
/// Build and package the project.
|
/// Build and package the project.
|
||||||
Package(subcommands::PackageArgs),
|
Package(subcommands::PackageArgs),
|
||||||
|
@ -31,6 +34,7 @@ impl Args {
|
||||||
match &self.cmd {
|
match &self.cmd {
|
||||||
Command::Init(args) => subcommands::init(self.verbose, args)?,
|
Command::Init(args) => subcommands::init(self.verbose, args)?,
|
||||||
Command::Build(args) => subcommands::build(self.verbose, args)?,
|
Command::Build(args) => subcommands::build(self.verbose, args)?,
|
||||||
|
Command::Clean(args) => subcommands::clean(self.verbose, args)?,
|
||||||
#[cfg(feature = "zip")]
|
#[cfg(feature = "zip")]
|
||||||
Command::Package(args) => subcommands::package(self.verbose, args)?,
|
Command::Package(args) => subcommands::package(self.verbose, args)?,
|
||||||
#[cfg(feature = "lang-debug")]
|
#[cfg(feature = "lang-debug")]
|
||||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -1,12 +1,14 @@
|
||||||
|
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() -> Result<()> {
|
fn main() -> ExitCode {
|
||||||
color_eyre::install()?;
|
color_eyre::install().unwrap();
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
args.run()?;
|
match args.run() {
|
||||||
|
Ok(_) => ExitCode::SUCCESS,
|
||||||
Ok(())
|
Err(_) => ExitCode::FAILURE,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use color_eyre::eyre::Result;
|
||||||
|
use path_absolutize::Absolutize;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
error::Error,
|
||||||
|
terminal_output::{print_error, print_info},
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Debug, clap::Args, Clone)]
|
||||||
|
pub struct CleanArgs {
|
||||||
|
/// The path of the project to clean.
|
||||||
|
#[clap(default_value = ".")]
|
||||||
|
pub path: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clean(_verbose: bool, args: &CleanArgs) -> Result<()> {
|
||||||
|
let path = args.path.as_path();
|
||||||
|
|
||||||
|
print_info(&format!(
|
||||||
|
"Cleaning project at {}",
|
||||||
|
path.absolutize_from(path)?.display()
|
||||||
|
));
|
||||||
|
|
||||||
|
let dist_path = path.join("dist");
|
||||||
|
|
||||||
|
if !path.join("pack.toml").exists() {
|
||||||
|
print_error("The specified directory is not a ShulkerScript project.");
|
||||||
|
return Err(Error::InvalidPackPathError(path.to_path_buf()).into());
|
||||||
|
}
|
||||||
|
|
||||||
|
if dist_path.exists() {
|
||||||
|
std::fs::remove_dir_all(&dist_path)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_info("Project cleaned successfully.");
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -4,6 +4,9 @@ pub use init::{init, InitArgs};
|
||||||
mod build;
|
mod build;
|
||||||
pub use build::{build, BuildArgs};
|
pub use build::{build, BuildArgs};
|
||||||
|
|
||||||
|
mod clean;
|
||||||
|
pub use clean::{clean, CleanArgs};
|
||||||
|
|
||||||
#[cfg(feature = "zip")]
|
#[cfg(feature = "zip")]
|
||||||
mod package;
|
mod package;
|
||||||
#[cfg(feature = "zip")]
|
#[cfg(feature = "zip")]
|
||||||
|
|
Loading…
Reference in New Issue