mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-20 12:45:05 +00:00
Modernize the plugin subcommand
This commit is contained in:
@@ -13,7 +13,7 @@ fn run(global: GlobalOptions, subcommand: Subcommand) -> anyhow::Result<()> {
|
||||
Subcommand::Upload(upload_options) => cli::upload(upload_options)?,
|
||||
Subcommand::FmtProject(subcommand) => subcommand.run()?,
|
||||
Subcommand::Doc(subcommand) => subcommand.run()?,
|
||||
Subcommand::Plugin(plugin_options) => cli::plugin(plugin_options)?,
|
||||
Subcommand::Plugin(subcommand) => subcommand.run()?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -25,7 +25,7 @@ pub use self::build::*;
|
||||
pub use self::doc::DocCommand;
|
||||
pub use self::fmt_project::FmtProjectCommand;
|
||||
pub use self::init::{InitCommand, InitKind};
|
||||
pub use self::plugin::*;
|
||||
pub use self::plugin::{PluginCommand, PluginSubcommand};
|
||||
pub use self::serve::*;
|
||||
pub use self::upload::*;
|
||||
|
||||
@@ -115,8 +115,6 @@ pub enum Subcommand {
|
||||
|
||||
FmtProject(FmtProjectCommand),
|
||||
Doc(DocCommand),
|
||||
|
||||
/// Manages Rojo's Roblox Studio plugin.
|
||||
Plugin(PluginCommand),
|
||||
}
|
||||
|
||||
@@ -238,21 +236,3 @@ fn resolve_path(path: &Path) -> Cow<'_, Path> {
|
||||
Cow::Owned(env::current_dir().unwrap().join(path))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub enum PluginSubcommand {
|
||||
/// Install the plugin in Roblox Studio's plugins folder. If the plugin is
|
||||
/// already installed, installing it again will overwrite the current plugin
|
||||
/// file.
|
||||
Install,
|
||||
|
||||
/// Removes the plugin if it is installed.
|
||||
Uninstall,
|
||||
}
|
||||
|
||||
/// Install Rojo's plugin.
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct PluginCommand {
|
||||
#[structopt(subcommand)]
|
||||
subcommand: PluginSubcommand,
|
||||
}
|
||||
|
||||
@@ -3,26 +3,50 @@ use std::{
|
||||
io::BufWriter,
|
||||
};
|
||||
|
||||
use anyhow::Result;
|
||||
use memofs::{InMemoryFs, Vfs, VfsSnapshot};
|
||||
use roblox_install::RobloxStudio;
|
||||
use structopt::StructOpt;
|
||||
|
||||
use crate::{
|
||||
cli::{PluginCommand, PluginSubcommand},
|
||||
serve_session::ServeSession,
|
||||
};
|
||||
use crate::serve_session::ServeSession;
|
||||
|
||||
static PLUGIN_BINCODE: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/plugin.bincode"));
|
||||
static PLUGIN_FILE_NAME: &str = "RojoManagedPlugin.rbxm";
|
||||
|
||||
pub fn plugin(options: PluginCommand) -> Result<()> {
|
||||
match options.subcommand {
|
||||
PluginSubcommand::Install => install_plugin(),
|
||||
PluginSubcommand::Uninstall => uninstall_plugin(),
|
||||
/// Install Rojo's plugin.
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct PluginCommand {
|
||||
#[structopt(subcommand)]
|
||||
subcommand: PluginSubcommand,
|
||||
}
|
||||
|
||||
/// Manages Rojo's Roblox Studio plugin.
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub enum PluginSubcommand {
|
||||
/// Install the plugin in Roblox Studio's plugins folder. If the plugin is
|
||||
/// already installed, installing it again will overwrite the current plugin
|
||||
/// file.
|
||||
Install,
|
||||
|
||||
/// Removes the plugin if it is installed.
|
||||
Uninstall,
|
||||
}
|
||||
|
||||
impl PluginCommand {
|
||||
pub fn run(self) -> anyhow::Result<()> {
|
||||
self.subcommand.run()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn install_plugin() -> Result<()> {
|
||||
impl PluginSubcommand {
|
||||
pub fn run(self) -> anyhow::Result<()> {
|
||||
match self {
|
||||
PluginSubcommand::Install => install_plugin(),
|
||||
PluginSubcommand::Uninstall => uninstall_plugin(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn install_plugin() -> anyhow::Result<()> {
|
||||
let plugin_snapshot: VfsSnapshot = bincode::deserialize(PLUGIN_BINCODE)
|
||||
.expect("Rojo's plugin was not properly packed into Rojo's binary");
|
||||
|
||||
@@ -54,7 +78,7 @@ pub fn install_plugin() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn uninstall_plugin() -> Result<()> {
|
||||
fn uninstall_plugin() -> anyhow::Result<()> {
|
||||
let studio = RobloxStudio::locate()?;
|
||||
|
||||
let plugin_path = studio.plugins_path().join(PLUGIN_FILE_NAME);
|
||||
|
||||
Reference in New Issue
Block a user