diff --git a/src/cli/build.rs b/src/cli/build.rs index d845e970..fff73fa4 100644 --- a/src/cli/build.rs +++ b/src/cli/build.rs @@ -78,7 +78,7 @@ fn build_inner(options: BuildCommand) -> Result<(), Error> { log::trace!("Constructing in-memory filesystem"); let vfs = Vfs::new(RealFetcher::new(WatchMode::Disabled)); - let (_maybe_project, tree) = common_setup::start(&options.project, &vfs); + let (_maybe_project, tree) = common_setup::start(&options.absolute_project(), &vfs); let root_id = tree.get_root_id(); log::trace!("Opening output file for write"); diff --git a/src/cli/mod.rs b/src/cli/mod.rs index e97737f1..20810002 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -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, } +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)) + } +} diff --git a/src/cli/serve.rs b/src/cli/serve.rs index 11e68baa..789cb2f1 100644 --- a/src/cli/serve.rs +++ b/src/cli/serve.rs @@ -28,7 +28,7 @@ pub fn serve(options: ServeCommand) -> Result<(), ServeError> { fn serve_inner(options: ServeCommand) -> Result<(), Error> { let vfs = Vfs::new(RealFetcher::new(WatchMode::Enabled)); - let session = Arc::new(ServeSession::new(vfs, &options.project)); + let session = Arc::new(ServeSession::new(vfs, &options.absolute_project())); let port = options .port diff --git a/src/cli/upload.rs b/src/cli/upload.rs index 4e14708a..42dca981 100644 --- a/src/cli/upload.rs +++ b/src/cli/upload.rs @@ -35,13 +35,14 @@ pub fn upload(options: UploadCommand) -> Result<(), UploadError> { fn upload_inner(options: UploadCommand) -> Result<(), Error> { let cookie = options .cookie + .clone() .or_else(get_auth_cookie) .ok_or(Error::NeedAuthCookie)?; log::trace!("Constructing in-memory filesystem"); let vfs = Vfs::new(RealFetcher::new(WatchMode::Disabled)); - let (_maybe_project, tree) = common_setup::start(&options.project, &vfs); + let (_maybe_project, tree) = common_setup::start(&options.absolute_project(), &vfs); let root_id = tree.get_root_id(); let mut buffer = Vec::new();