mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-22 21:55:15 +00:00
Fix live sync.
The refactor to use StructOpt instead of plain Clap had some absolute vs relative path issues that slipped through. This commit adds getters to each StructOpt struct that exposes an explicitly absolute version of each path value.
This commit is contained in:
@@ -5,7 +5,14 @@ mod init;
|
||||
mod serve;
|
||||
mod upload;
|
||||
|
||||
use std::{error::Error, fmt, path::PathBuf, str::FromStr};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
env,
|
||||
error::Error,
|
||||
fmt,
|
||||
path::{Path, PathBuf},
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
use structopt::StructOpt;
|
||||
|
||||
@@ -55,6 +62,12 @@ pub struct InitCommand {
|
||||
pub kind: InitKind,
|
||||
}
|
||||
|
||||
impl InitCommand {
|
||||
pub fn absolute_path(&self) -> Cow<'_, Path> {
|
||||
resolve_path(&self.path)
|
||||
}
|
||||
}
|
||||
|
||||
/// The templates we support for initializing a Rojo project.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum InitKind {
|
||||
@@ -111,6 +124,12 @@ pub struct ServeCommand {
|
||||
pub port: Option<u16>,
|
||||
}
|
||||
|
||||
impl ServeCommand {
|
||||
pub fn absolute_project(&self) -> Cow<'_, Path> {
|
||||
resolve_path(&self.project)
|
||||
}
|
||||
}
|
||||
|
||||
/// Build a Rojo project into a file.
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct BuildCommand {
|
||||
@@ -123,6 +142,12 @@ pub struct BuildCommand {
|
||||
pub output: PathBuf,
|
||||
}
|
||||
|
||||
impl BuildCommand {
|
||||
pub fn absolute_project(&self) -> Cow<'_, Path> {
|
||||
resolve_path(&self.project)
|
||||
}
|
||||
}
|
||||
|
||||
/// Build and upload a Rojo project to Roblox.com.
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct UploadCommand {
|
||||
@@ -143,6 +168,12 @@ pub struct UploadCommand {
|
||||
pub asset_id: u64,
|
||||
}
|
||||
|
||||
impl UploadCommand {
|
||||
pub fn absolute_project(&self) -> Cow<'_, Path> {
|
||||
resolve_path(&self.project)
|
||||
}
|
||||
}
|
||||
|
||||
/// The kind of asset to upload to the website. Affects what endpoints Rojo uses
|
||||
/// and changes how the asset is built.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
@@ -185,3 +216,11 @@ impl fmt::Display for UploadKindParseError {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_path(path: &Path) -> Cow<'_, Path> {
|
||||
if path.is_absolute() {
|
||||
Cow::Borrowed(path)
|
||||
} else {
|
||||
Cow::Owned(env::current_dir().unwrap().join(path))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user