Skip to content

Commit

Permalink
Merge pull request #82 from tsirysndr/feat/run-subcommand
Browse files Browse the repository at this point in the history
cli: add run subcommand and remove dependency on external deno command
  • Loading branch information
tsirysndr authored Jan 8, 2025
2 parents bdb67cf + 1a10c65 commit 039d720
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ MacOS, currently not supported, but you can run in a docker container.

## 📦 Downloads

- `Linux`: intel: [rockbox_2025.01.07_x86_64-linux.tar.gz](https://github.com/tsirysndr/rockbox-zig/releases/download/2025.01.07/rockbox_2025.01.07_x86_64-linux.tar.gz) arm64: [rockbox_2025.01.07_aarch64-linux.tar.gz](https://github.com/tsirysndr/rockbox-zig/releases/download/2025.01.07/rockbox_2025.01.07_aarch64-linux.tar.gz)
- `Linux`: intel: [rockbox_2025.01.08_x86_64-linux.tar.gz](https://github.com/tsirysndr/rockbox-zig/releases/download/2025.01.08/rockbox_2025.01.08_x86_64-linux.tar.gz) arm64: [rockbox_2025.01.08_aarch64-linux.tar.gz](https://github.com/tsirysndr/rockbox-zig/releases/download/2025.01.08/rockbox_2025.01.08_aarch64-linux.tar.gz)

## ✨ Features

Expand Down
1 change: 1 addition & 0 deletions cli/src/cmd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod community;
pub mod repl;
pub mod run;
pub mod scan;
pub mod start;
pub mod webui;
5 changes: 3 additions & 2 deletions cli/src/cmd/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ macro_rules! svec {
}

pub fn repl() {
let handle = thread::spawn(|| {
deno::cli(svec!["deno", "repl", "-A"]);
let handle = thread::spawn(|| match deno::cli(svec!["deno", "repl", "-A"]) {
Ok(_) => {}
Err(_) => {}
});
handle.join().unwrap();
}
9 changes: 9 additions & 0 deletions cli/src/cmd/run.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use std::{ffi::OsString, thread};

pub fn run(args: Vec<OsString>) {
let handle = thread::spawn(move || match deno::cli(args) {
Ok(_) => {}
Err(_) => {}
});
handle.join().unwrap();
}
3 changes: 1 addition & 2 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ pub fn install_rockboxd() -> Result<(), Error> {
}

pub fn wait_for_rockboxd(port: u32, timeout: Option<u32>) -> Result<(), Error> {
setup_pkgx()?;
let cmd = format!(
"pkgx deno run -A npm:wait-port localhost:{} -t {}",
"rockbox run -A npm:wait-port localhost:{} -t {}",
port,
timeout.unwrap_or(60) * 1000
);
Expand Down
24 changes: 23 additions & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::ffi::OsString;

use anyhow::Error;
use clap::{arg, Command};
use owo_colors::OwoColorize;

use cmd::{community::*, repl::*, scan::*, start::*, webui::*};
use cmd::{community::*, repl::*, run::*, scan::*, start::*, webui::*};

pub mod cmd;

Expand Down Expand Up @@ -46,10 +48,30 @@ fn cli() -> Command {
.about("Start the Rockbox REPL")
.visible_alias("shell"),
)
.subcommand(
Command::new("run")
.arg(arg!(<FILE> "JavaScript or TypeScript file to run"))
.about("Run a JavaScript or TypeScript program")
.visible_alias("x"),
)
}

#[tokio::main]
async fn main() -> Result<(), Error> {
let args = std::env::args().collect::<Vec<String>>();
if args.len() > 1 && args[1] == "run" {
let _args = args
.into_iter()
.map(|s| match s.as_str() {
"rockbox" => "deno".into(),
_ => s.into(),
})
.collect::<Vec<OsString>>();

run(_args);
return Ok(());
}

let matches = cli().get_matches();

match matches.subcommand() {
Expand Down
2 changes: 0 additions & 2 deletions crates/mpd/src/handlers/system.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::os::unix::thread;

use anyhow::Error;
use tokio::sync::mpsc::Sender;

Expand Down
2 changes: 1 addition & 1 deletion deno
Submodule deno updated 1 files
+23 −2 cli/lib.rs

0 comments on commit 039d720

Please sign in to comment.