Modernize the plugin subcommand

This commit is contained in:
Lucien Greathouse
2021-05-21 13:09:07 -04:00
parent afe26b8c16
commit 7f230a8bf4
3 changed files with 37 additions and 33 deletions

View File

@@ -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(())

View File

@@ -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,
}

View File

@@ -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);