forked from rojo-rbx/rojo
Add fmt-project subcommand
This commit is contained in:
@@ -11,6 +11,7 @@ fn run(global: GlobalOptions, subcommand: Subcommand) -> anyhow::Result<()> {
|
||||
Subcommand::Serve(serve_options) => cli::serve(global, serve_options)?,
|
||||
Subcommand::Build(build_options) => cli::build(build_options)?,
|
||||
Subcommand::Upload(upload_options) => cli::upload(upload_options)?,
|
||||
Subcommand::FmtProject(fmt_options) => fmt_options.run()?,
|
||||
Subcommand::Doc => cli::doc()?,
|
||||
Subcommand::Plugin(plugin_options) => cli::plugin(plugin_options)?,
|
||||
}
|
||||
|
||||
29
src/cli/fmt_project.rs
Normal file
29
src/cli/fmt_project.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::Context;
|
||||
use structopt::StructOpt;
|
||||
|
||||
use crate::project::Project;
|
||||
|
||||
/// Reformat a Rojo project using the standard JSON formatting rules.
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct FmtProjectCommand {
|
||||
/// Path to the project to format. Defaults to the current directory.
|
||||
#[structopt(default_value = "")]
|
||||
pub project: PathBuf,
|
||||
}
|
||||
|
||||
impl FmtProjectCommand {
|
||||
pub fn run(self) -> anyhow::Result<()> {
|
||||
let project = Project::load_fuzzy(&self.project)?
|
||||
.context("A project file is required to run 'rojo fmt-project'")?;
|
||||
|
||||
let serialized = serde_json::to_string_pretty(&project)
|
||||
.context("could not re-encode project file as JSON")?;
|
||||
|
||||
fs_err::write(&project.file_location, &serialized)
|
||||
.context("could not write back to project file")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
mod build;
|
||||
mod doc;
|
||||
mod fmt_project;
|
||||
mod init;
|
||||
mod plugin;
|
||||
mod serve;
|
||||
@@ -22,6 +23,7 @@ use thiserror::Error;
|
||||
|
||||
pub use self::build::*;
|
||||
pub use self::doc::*;
|
||||
pub use self::fmt_project::FmtProjectCommand;
|
||||
pub use self::init::*;
|
||||
pub use self::plugin::*;
|
||||
pub use self::serve::*;
|
||||
@@ -112,6 +114,8 @@ pub enum Subcommand {
|
||||
/// Generates a place or model file out of the project and uploads it to Roblox.
|
||||
Upload(UploadCommand),
|
||||
|
||||
FmtProject(FmtProjectCommand),
|
||||
|
||||
/// Open Rojo's documentation in your browser.
|
||||
Doc,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user