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.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["Firefly Zero team"]
description = "CLI tool for working with Firefly Zero"
homepage = "https://fireflyzero.com/"
repository = "https://github.com/firefly-zero/firefly-cli"
license = "MIT"
license = "GPL-3.0"
keywords = ["gamedev", "firefly-zero", "cli"]
categories = [
"command-line-utilities",
Expand Down
57 changes: 50 additions & 7 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pub enum Commands {
#[clap(hide = true)]
Postinstall(PostinstallArgs),

/// Build the project, run it in emulator, and export the ROM.
Run(BuildArgs),

/// Build the project and install it locally (into VFS).
Build(BuildArgs),

Expand Down Expand Up @@ -130,10 +133,6 @@ pub struct BuildArgs {
#[arg(default_value = ".")]
pub root: PathBuf,

/// Path to the directory where to store roms
#[arg(short, long, default_value = None)]
pub roms: Option<PathBuf>,

/// Path to the firefly config.
#[arg(short, long, default_value = None)]
pub config: Option<PathBuf>,
Expand Down Expand Up @@ -210,14 +209,58 @@ pub struct NewArgs {
pub lang: String,
}

#[derive(Debug, Parser)]
#[derive(Debug, Parser, Default)]
pub struct EmulatorArgs {
/// Download the latest emulator release.
#[arg(long, default_value_t = false)]
pub update: bool,

/// Arguments to pass into the emulator.
pub args: Vec<String>,
/// The scale for the window and each pixel.
///
/// Must be a power of 2: 1, 2, 4, 8, 16, or 32.
#[arg(long, default_value = None)]
pub scale: Option<String>,

/// Run the emulator in borderless mode and scale to fit the screen.
///
/// If specified, "--scale" has no effect.
#[arg(long, default_value_t = false)]
pub fullscreen: bool,

/// The full ID of the app to run.
///
/// If not specified, will start launcher (if installed) or the latest installed app.
#[arg(long, default_value = None)]
pub id: Option<String>,

/// The TCP IP address where to listen for serial events.
#[arg(long, default_value = None)]
pub tcp_ip: Option<String>,

/// The UDP IP address where to listen for netplay events.
#[arg(long, default_value = None)]
pub udp_ip: Option<String>,

/// The UDP IP addresses where to send netplay advertisements.
#[arg(long, default_value = None)]
pub peers: Option<String>,

/// Path to the virtual FS to use.
///
/// By default, the global one (~/.local/share/firefly) is used.
#[arg(long, default_value = None)]
pub vfs: Option<String>,

/// If provided, the path where to save the audio output (as a WAV file).
#[arg(long, default_value = None)]
pub wav: Option<String>,

/// Disable reading input from keyboard.
///
/// Useful if you have troubles with keyboard (like a stuck key)
/// and just want to use gamepad as input.
#[arg(long, default_value_t = false)]
pub no_keyboard: bool,
}

#[derive(Debug, Parser)]
Expand Down
1 change: 1 addition & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub fn run_command(vfs: PathBuf, command: &Commands) -> anyhow::Result<()> {
Boards(args) => cmd_boards(&vfs, args),
Inspect(args) => cmd_inspect(&vfs, args),
Repl(args) => cmd_repl(&vfs, args),
Run(args) => cmd_run(&vfs, args),
Shots(ShotsCommands::Download(args)) => cmd_shots_download(&vfs, args),
Catalog(command) => match command {
CatalogCommands::List(args) => cmd_catalog_list(args),
Expand Down
45 changes: 44 additions & 1 deletion src/commands/emulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,54 @@ pub fn cmd_emulator(vfs: &Path, args: &EmulatorArgs) -> Result<()> {
download_emulator(&bin_path).context("download emulator")?;
}
println!("⌛ running...");
let exit_status = Command::new(bin_path).args(&args.args).status()?;
let exit_status = Command::new(bin_path).args(format_args(args)).status()?;
check_exit_status(exit_status).context("run emulator")?;
Ok(())
}

fn format_args(args: &EmulatorArgs) -> Vec<&str> {
let mut res = Vec::new();
if args.update {
res.push("--update");
}
if args.fullscreen {
res.push("--fullscreen");
}
if args.no_keyboard {
res.push("--no_keyboard");
}

if let Some(val) = &args.scale {
res.push("--scale");
res.push(val);
}
if let Some(val) = &args.id {
res.push("--id");
res.push(val);
}
if let Some(val) = &args.tcp_ip {
res.push("--tcp_ip");
res.push(val);
}
if let Some(val) = &args.udp_ip {
res.push("--udp_ip");
res.push(val);
}
if let Some(val) = &args.peers {
res.push("--peers");
res.push(val);
}
if let Some(val) = &args.vfs {
res.push("--vfs");
res.push(val);
}
if let Some(val) = &args.wav {
res.push("--wav");
res.push(val);
}
res
}

fn download_emulator(bin_path: &Path) -> Result<()> {
// Send HTTP request.
let url = get_release_url();
Expand Down
2 changes: 2 additions & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod monitor;
mod new;
mod postinstall;
mod repl;
mod run;
mod runtime;
mod shots;
mod test;
Expand All @@ -31,6 +32,7 @@ pub use monitor::cmd_monitor;
pub use new::cmd_new;
pub use postinstall::cmd_postinstall;
pub use repl::cmd_repl;
pub use run::cmd_run;
pub use runtime::{cmd_exit, cmd_id, cmd_launch, cmd_restart, cmd_screenshot};
pub use shots::cmd_shots_download;
pub use test::cmd_test;
Expand Down
27 changes: 27 additions & 0 deletions src/commands/run.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use crate::args::{BuildArgs, EmulatorArgs, ExportArgs};
use crate::commands::{cmd_build, cmd_emulator, cmd_export};
use crate::config::Config;
use anyhow::{Context, Result};
use std::path::Path;

pub fn cmd_run(vfs: &Path, build_args: &BuildArgs) -> Result<()> {
let config =
Config::load(vfs.to_path_buf(), &build_args.root).context("load project config")?;
let id = format!("{}.{}", config.author_id, config.app_id);

cmd_build(vfs.to_path_buf(), build_args).context("build")?;

let emulator_args = EmulatorArgs {
id: Some(id.clone()),
..Default::default()
};
cmd_emulator(vfs, &emulator_args).context("emulator")?;

let export_args = ExportArgs {
root: build_args.root.clone(),
id: Some(id),
output: None,
};
cmd_export(vfs, &export_args).context("export")?;
Ok(())
}
Loading