Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ homepage = "https://oseda.net"
repository = "https://github.com/oseda-dev/oseda-cli"
readme = "README.md"
name = "oseda-cli"
version = "3.2.1"
version = "3.2.2"
edition = "2021"

[[bin]]
Expand Down
11 changes: 10 additions & 1 deletion src/cmd/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
use clap::Args;
use reqwest::StatusCode;

use crate::cmd::run;
use crate::cmd::{is_cwd_oseda_project, run};
use crate::config;

use crate::net::{self, kill_port};
Expand All @@ -32,6 +32,7 @@ pub enum OsedaCheckError {
CouldNotPingLocalPresentation(String),
MissingDescription(String),
MissingTags(String),
NotOsedaProject(String),
}

impl std::error::Error for OsedaCheckError {}
Expand All @@ -55,6 +56,9 @@ impl std::fmt::Display for OsedaCheckError {
Self::MissingTags(msg) => {
write!(f, "No tags detected: {}", msg)
}
Self::NotOsedaProject(msg) => {
write!(f, "Not an Oseda project: {}", msg)
}
}
}
}
Expand All @@ -68,6 +72,11 @@ impl std::fmt::Display for OsedaCheckError {
/// * `Ok(())` if the project passes all checks and is considered as "deployabl"e
/// * `Err(OsedaCheckError)` a problem was detected that prevents the user from doing a deployment
pub fn check(opts: CheckOptions) -> Result<(), OsedaCheckError> {

if !is_cwd_oseda_project(){
return Err(OsedaCheckError::NotOsedaProject("Cannot check non-project".to_owned()));
}

// separate abstraction layer here, want the primary subcommand to call this
// verify can also be called from deploy (in theory)
match verify_project(opts.port) {
Expand Down
8 changes: 6 additions & 2 deletions src/cmd/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use std::{env, error::Error, fs, path::Path};
use clap::Args;

use crate::{
config,
github::{self, git},
cmd::is_cwd_oseda_project, config, github::{self, git}
};

/// Options for the `oseda deploy` command
Expand Down Expand Up @@ -64,6 +63,11 @@ impl TryFrom<String> for SshUrl {
/// * `Ok(())` on success
/// * `Err` if any git, file, or config step fails, including a check failure
pub fn deploy(opts: DeployOptions) -> Result<(), Box<dyn Error>> {

if !is_cwd_oseda_project() {
return Err("Current working directory is not an Oseda project".into());
}

let tmp_dir = tempfile::tempdir()?;
let repo_path = tmp_dir.path();

Expand Down
14 changes: 8 additions & 6 deletions src/cmd/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{

use clap::Args;

use crate::cmd::run::is_cwd_oseda_project;
use crate::cmd::is_cwd_oseda_project;

/// Options for the `oseda dev` command
#[derive(Args, Debug, Clone)]
Expand Down Expand Up @@ -49,6 +49,12 @@ impl std::fmt::Display for OsedaDevError {
/// * `Ok()` on success
/// * `Err` on any issue related to running oseda in dev mode
pub fn dev(opts: DevOptions) -> Result<(), OsedaDevError> {
if !is_cwd_oseda_project() {
return Err(OsedaDevError::NotOsedaProjectError(
"oseda-config.json not found".to_string(),
));
}

dev_with_shutdown(opts, Arc::new(AtomicBool::new(false)))
}

Expand All @@ -65,11 +71,7 @@ pub fn dev_with_shutdown(
opts: DevOptions,
shutdown_flag: Arc<AtomicBool>,
) -> Result<(), OsedaDevError> {
if !is_cwd_oseda_project() {
return Err(OsedaDevError::NotOsedaProjectError(
"oseda-config.json not found".to_string(),
));
}


let mut cmd = Command::new("npx");
cmd.arg("vite")
Expand Down
7 changes: 6 additions & 1 deletion src/cmd/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
use clap::Args;

use crate::{
cmd::run,
cmd::{is_cwd_oseda_project, run},
config::read_and_validate_config,
net::kill_port,
puppeteer::{is_puppeteer_chrome_installed, prompt_install_puppeteer_chrome},
Expand Down Expand Up @@ -46,6 +46,11 @@ fn get_default_output() -> String {

/// Export the current Oseda project to a PDF file via `decktape`
pub fn export(opts: ExportOptions) -> Result<(), Box<dyn Error>> {

if !is_cwd_oseda_project() {
return Err("Current working directory is not an Oseda project".into())
}

println!("Cleaning any existing oseda processing...");
if kill_port(opts.port).is_err() {
eprintln!("Warning, could not kill value on desired port")
Expand Down
10 changes: 10 additions & 0 deletions src/cmd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use std::path::Path;

use crate::config;

pub mod check;
pub mod deploy;
pub mod dev;
Expand All @@ -6,3 +10,9 @@ pub mod fork;
pub mod init;
pub mod run;
pub mod update;

pub fn is_cwd_oseda_project() -> bool {
Path::new(config::CONFIG_FILE_NAME)
.try_exists()
.is_ok_and(|exists| exists)
}
21 changes: 8 additions & 13 deletions src/cmd/run.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::{
path::Path,
process::Command,
sync::{
atomic::{AtomicBool, Ordering},
Expand All @@ -8,7 +7,7 @@ use std::{
time::Duration,
};

use crate::config::{self};
use crate::cmd::is_cwd_oseda_project;

/// More in depth errors that could cause a project not to run
#[derive(Debug)]
Expand Down Expand Up @@ -44,23 +43,19 @@ impl std::fmt::Display for OsedaRunError {
/// * `Ok(())` if both the build and serve steps succeed
/// * `Err(OsedaRunError)` if any step fails (missing vite isn't installed, or `serve` fails to start)
pub fn run() -> Result<(), OsedaRunError> {
run_with_shutdown(Arc::new(AtomicBool::new(false)))
}

pub fn is_cwd_oseda_project() -> bool {
Path::new(config::CONFIG_FILE_NAME)
.try_exists()
.is_ok_and(|exists| exists)
}

pub fn run_with_shutdown(shutdown_flag: Arc<AtomicBool>) -> Result<(), OsedaRunError> {
// command run failure and command status are considered different, handled accordingly
if !is_cwd_oseda_project() {
return Err(OsedaRunError::NotOsedaProjectError(
"oseda-config.json not found".to_string(),
));
}

run_with_shutdown(Arc::new(AtomicBool::new(false)))
}

pub fn run_with_shutdown(shutdown_flag: Arc<AtomicBool>) -> Result<(), OsedaRunError> {
// command run failure and command status are considered different, handled accordingly


match Command::new("npx").arg("vite").arg("build").status() {
Ok(status) => {
if !status.success() {
Expand Down
Loading