Skip to content

Don't rewrite it in Rust. Rewrite the 5% that's slow: profile your app, port the hot functions with your coding agent, prove they behave the same. Python, JS/TS, Ruby, Java, Kotlin, Go, PHP, C/C++, C#, R.

disable --all: switch every port back at once (#41)

chessMan7d0d0143a022
diff --git a/src/main.rs b/src/main.rs
index ea38a76..9089878 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -95,7 +95,12 @@ enum Cmd {
force: bool,
},
/// Switch back to the original code
- Disable { id: Option<String> },
+ Disable {
+ id: Option<String>,
+ /// Switch every enabled port back
+ #[arg(long, conflicts_with = "id")]
+ all: bool,
+ },
/// Rebuild every port (after cloning, or a toolchain upgrade)
Build,
/// Time your app with the originals vs the Rust ports
@@ -175,7 +180,17 @@ fn run(cmd: Cmd, root: &Path) -> Result<()> {
show::next("fast-anything bench");
Ok(())
}
- Cmd::Disable { id } => {
+ Cmd::Disable { all: true, .. } => {
+ let ids = pipeline::disable_all(root)?;
+ if ids.is_empty() {
+ ui::ok("no port was switched on");
+ }
+ for id in ids {
+ ui::ok(format!("{} is back to the original code", ui::bold(&id)));
+ }
+ Ok(())
+ }
+ Cmd::Disable { id, .. } => {
let id = pipeline::disable(root, id.as_deref())?;
ui::ok(format!("{} is back to the original code", ui::bold(&id)));
Ok(())
@@ -203,6 +218,15 @@ fn run(cmd: Cmd, root: &Path) -> Result<()> {
mod tests {
use super::*;
+ #[test]
+ fn disable_all_parses() {
+ assert!(matches!(
+ Cli::try_parse_from(["fast-anything", "disable", "--all"]).unwrap().cmd,
+ Cmd::Disable { all: true, id: None }
+ ));
+ assert!(Cli::try_parse_from(["fast-anything", "disable", "fuzzy.lev", "--all"]).is_err());
+ }
+
#[test]
fn verify_all_parses() {
let cli = Cli::try_parse_from(["fast-anything", "verify", "--all"]).unwrap();
diff --git a/src/pipeline.rs b/src/pipeline.rs
index e85fc0e..9b99747 100644
--- a/src/pipeline.rs
+++ b/src/pipeline.rs
@@ -254,6 +254,15 @@ pub fn disable(root: &Path, id: Option<&str>) -> Result<String> {
Ok(id)
}
+/// Switch every enabled port back to the original code; returns their ids.
+pub fn disable_all(root: &Path) -> Result<Vec<String>> {
+ let ids: Vec<String> = Ctx::open(root)?.state.ports.values().filter(|p| p.enabled).map(|p| p.id.clone()).collect();
+ for id in &ids {
+ disable(root, Some(id))?;
+ }
+ Ok(ids)
+}
+
pub fn build_all(root: &Path) -> Result<()> {
let ctx = Ctx::open(root)?;
ensure!(!ctx.state.ports.is_empty(), "nothing ported yet");