This is an automated email from the ASF dual-hosted git repository.

tisonkun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datasketches-rust.git


The following commit(s) were added to refs/heads/main by this push:
     new abdaaf7  refactor(xtask): split subcommands into dedicated modules 
(#383)
abdaaf7 is described below

commit abdaaf78db15b6577da083ed33dc959472966cd7
Author: tison <[email protected]>
AuthorDate: Wed Nov 18 17:44:15 2026 +0800

    refactor(xtask): split subcommands into dedicated modules (#383)
---
 xtask/src/bench.rs |  54 ++++++++++++++
 xtask/src/check.rs |  57 +++++++++++++++
 xtask/src/docs.rs  |  50 +++++++++++++
 xtask/src/lint.rs  | 104 +++++++++++++++++++++++++++
 xtask/src/main.rs  | 206 +++--------------------------------------------------
 xtask/src/test.rs  |  49 +++++++++++++
 6 files changed, 324 insertions(+), 196 deletions(-)

diff --git a/xtask/src/bench.rs b/xtask/src/bench.rs
new file mode 100644
index 0000000..a5d7fe8
--- /dev/null
+++ b/xtask/src/bench.rs
@@ -0,0 +1,54 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::process::Command as StdCommand;
+
+use clap::Parser;
+
+use crate::find_command;
+use crate::run_command;
+
+#[derive(Parser)]
+pub struct CommandBench {
+    #[arg(long, help = "Compile benchmarks without running them.")]
+    no_run: bool,
+
+    #[arg(
+        last = true,
+        conflicts_with = "no_run",
+        help = "Arguments passed to the benchmark runner."
+    )]
+    args: Vec<String>,
+}
+
+impl CommandBench {
+    pub fn run(self) {
+        run_command(make_bench_cmd(self.no_run, &self.args));
+    }
+}
+
+fn make_bench_cmd(no_run: bool, args: &[String]) -> StdCommand {
+    let mut cmd = find_command("cargo");
+    cmd.args(["bench", "--package", "benchmarks", "--bench", "benchmarks"]);
+    if no_run {
+        cmd.arg("--no-run");
+    }
+    if !args.is_empty() {
+        cmd.arg("--").args(args);
+    }
+    cmd
+}
diff --git a/xtask/src/check.rs b/xtask/src/check.rs
new file mode 100644
index 0000000..a252dd2
--- /dev/null
+++ b/xtask/src/check.rs
@@ -0,0 +1,57 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::process::Command as StdCommand;
+
+use clap::Parser;
+
+use crate::datasketches_features;
+use crate::find_command;
+use crate::run_command;
+
+#[derive(Parser)]
+#[clap(name = "check")]
+pub struct CommandCheck {}
+
+impl CommandCheck {
+    pub fn run(self) {
+        let features = datasketches_features();
+
+        run_command(make_check_cmd(&[]));
+        for feature in features.chunks(1) {
+            run_command(make_check_cmd(feature));
+        }
+        run_command(make_check_cmd(&features));
+    }
+}
+
+fn make_check_cmd(features: &[String]) -> StdCommand {
+    let mut cmd = find_command("cargo");
+    cmd.env("RUSTFLAGS", "-Dwarnings");
+    cmd.args([
+        "+nightly",
+        "check",
+        "--package",
+        "datasketches",
+        "--all-targets",
+        "--no-default-features",
+    ]);
+    for feature in features {
+        cmd.args(["--features", feature]);
+    }
+    cmd
+}
diff --git a/xtask/src/docs.rs b/xtask/src/docs.rs
new file mode 100644
index 0000000..842f65b
--- /dev/null
+++ b/xtask/src/docs.rs
@@ -0,0 +1,50 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::process::Command as StdCommand;
+
+use clap::Parser;
+
+use crate::find_command;
+use crate::run_command;
+
+#[derive(Parser)]
+#[clap(name = "docs")]
+pub struct CommandDocs {}
+
+impl CommandDocs {
+    pub fn run(self) {
+        run_command(make_docs_cmd(true));
+    }
+}
+
+pub fn make_docs_cmd(open: bool) -> StdCommand {
+    let mut cmd = find_command("cargo");
+    cmd.env("RUSTDOCFLAGS", "--cfg docsrs -D warnings");
+    cmd.args([
+        "+nightly",
+        "doc",
+        "--package",
+        "datasketches",
+        "--all-features",
+        "--no-deps",
+    ]);
+    if open {
+        cmd.args(["--open"]);
+    }
+    cmd
+}
diff --git a/xtask/src/lint.rs b/xtask/src/lint.rs
new file mode 100644
index 0000000..e3f16b7
--- /dev/null
+++ b/xtask/src/lint.rs
@@ -0,0 +1,104 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::process::Command as StdCommand;
+
+use clap::Parser;
+
+use crate::docs::make_docs_cmd;
+use crate::find_command;
+use crate::run_command;
+
+#[derive(Parser)]
+#[clap(name = "lint")]
+pub struct CommandLint {
+    #[arg(long, help = "Automatically apply lint suggestions.")]
+    fix: bool,
+}
+
+impl CommandLint {
+    pub fn run(self) {
+        run_command(make_clippy_cmd(self.fix));
+        run_command(make_format_cmd(self.fix));
+        run_command(make_docs_cmd(false));
+        run_command(make_taplo_cmd(self.fix));
+        run_command(make_typos_cmd());
+        run_command(make_hawkeye_cmd(self.fix));
+    }
+}
+
+fn ensure_installed(bin: &str, crate_name: &str) {
+    if which::which(bin).is_err() {
+        let mut cmd = find_command("cargo");
+        cmd.args(["install", crate_name]);
+        run_command(cmd);
+    }
+}
+
+fn make_format_cmd(fix: bool) -> StdCommand {
+    let mut cmd = find_command("cargo");
+    cmd.args(["+nightly", "fmt", "--all"]);
+    if !fix {
+        cmd.arg("--check");
+    }
+    cmd
+}
+
+fn make_clippy_cmd(fix: bool) -> StdCommand {
+    let mut cmd = find_command("cargo");
+    cmd.args([
+        "+nightly",
+        "clippy",
+        "--tests",
+        "--all-features",
+        "--all-targets",
+        "--workspace",
+    ]);
+    if fix {
+        cmd.args(["--allow-staged", "--allow-dirty", "--fix"]);
+    } else {
+        cmd.args(["--", "-D", "warnings"]);
+    }
+    cmd
+}
+
+fn make_hawkeye_cmd(fix: bool) -> StdCommand {
+    ensure_installed("hawkeye", "hawkeye");
+    let mut cmd = find_command("hawkeye");
+    if fix {
+        cmd.args(["format"]);
+    } else {
+        cmd.args(["check"]);
+    }
+    cmd
+}
+
+fn make_typos_cmd() -> StdCommand {
+    ensure_installed("typos", "typos-cli");
+    find_command("typos")
+}
+
+fn make_taplo_cmd(fix: bool) -> StdCommand {
+    ensure_installed("taplo", "taplo-cli");
+    let mut cmd = find_command("taplo");
+    if fix {
+        cmd.args(["format"]);
+    } else {
+        cmd.args(["format", "--check"]);
+    }
+    cmd
+}
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index 46f72a4..6d2c910 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -15,7 +15,12 @@
 // specific language governing permissions and limitations
 // under the License.
 
+mod bench;
+mod check;
+mod docs;
+mod lint;
 mod prepare_testdata;
+mod test;
 
 use std::path::Path;
 use std::process::Command as StdCommand;
@@ -23,7 +28,12 @@ use std::process::Command as StdCommand;
 use clap::Parser;
 use clap::Subcommand;
 
+use crate::bench::CommandBench;
+use crate::check::CommandCheck;
+use crate::docs::CommandDocs;
+use crate::lint::CommandLint;
 use crate::prepare_testdata::CommandPrepareTestData;
+use crate::test::CommandTest;
 
 fn main() {
     let cmd = Command::parse();
@@ -68,64 +78,6 @@ enum SubCommand {
     PrepareTestData(CommandPrepareTestData),
 }
 
-#[derive(Parser)]
-struct CommandBench {
-    #[arg(long, help = "Compile benchmarks without running them.")]
-    no_run: bool,
-
-    #[arg(
-        last = true,
-        conflicts_with = "no_run",
-        help = "Arguments passed to the benchmark runner."
-    )]
-    args: Vec<String>,
-}
-
-impl CommandBench {
-    fn run(self) {
-        run_command(make_bench_cmd(self.no_run, &self.args));
-    }
-}
-
-#[derive(Parser)]
-#[clap(name = "check")]
-struct CommandCheck {}
-
-impl CommandCheck {
-    fn run(self) {
-        let features = datasketches_features();
-
-        run_command(make_check_cmd(&[]));
-        for feature in features.chunks(1) {
-            run_command(make_check_cmd(feature));
-        }
-        run_command(make_check_cmd(&features));
-    }
-}
-
-#[derive(Parser)]
-#[clap(name = "docs")]
-struct CommandDocs {}
-
-impl CommandDocs {
-    fn run(self) {
-        run_command(make_docs_cmd(true));
-    }
-}
-
-#[derive(Parser)]
-struct CommandTest {
-    #[arg(long, help = "Run tests serially and do not capture output.")]
-    no_capture: bool,
-}
-
-impl CommandTest {
-    fn run(self) {
-        let features = datasketches_features();
-        run_command(make_test_cmd(self.no_capture, &features));
-    }
-}
-
 fn datasketches_features() -> Vec<String> {
     use cargo_metadata::Metadata;
     use cargo_metadata::MetadataCommand;
@@ -151,24 +103,6 @@ fn datasketches_features() -> Vec<String> {
     features
 }
 
-#[derive(Parser)]
-#[clap(name = "lint")]
-struct CommandLint {
-    #[arg(long, help = "Automatically apply lint suggestions.")]
-    fix: bool,
-}
-
-impl CommandLint {
-    fn run(self) {
-        run_command(make_clippy_cmd(self.fix));
-        run_command(make_format_cmd(self.fix));
-        run_command(make_docs_cmd(false));
-        run_command(make_taplo_cmd(self.fix));
-        run_command(make_typos_cmd());
-        run_command(make_hawkeye_cmd(self.fix));
-    }
-}
-
 fn find_command(cmd: &str) -> StdCommand {
     match which::which(cmd) {
         Ok(exe) => {
@@ -182,128 +116,8 @@ fn find_command(cmd: &str) -> StdCommand {
     }
 }
 
-fn ensure_installed(bin: &str, crate_name: &str) {
-    if which::which(bin).is_err() {
-        let mut cmd = find_command("cargo");
-        cmd.args(["install", crate_name]);
-        run_command(cmd);
-    }
-}
-
 fn run_command(mut cmd: StdCommand) {
     println!("{cmd:?}");
     let status = cmd.status().expect("failed to execute process");
     assert!(status.success(), "command failed: {status}");
 }
-
-fn make_bench_cmd(no_run: bool, args: &[String]) -> StdCommand {
-    let mut cmd = find_command("cargo");
-    cmd.args(["bench", "--package", "benchmarks", "--bench", "benchmarks"]);
-    if no_run {
-        cmd.arg("--no-run");
-    }
-    if !args.is_empty() {
-        cmd.arg("--").args(args);
-    }
-    cmd
-}
-
-fn make_test_cmd(no_capture: bool, features: &[String]) -> StdCommand {
-    let mut cmd = find_command("cargo");
-    cmd.args(["test", "--workspace", "--no-default-features"]);
-    for feature in features {
-        cmd.args(["--features", feature]);
-    }
-    if no_capture {
-        cmd.args(["--", "--nocapture"]);
-    }
-    cmd
-}
-
-fn make_check_cmd(features: &[String]) -> StdCommand {
-    let mut cmd = find_command("cargo");
-    cmd.env("RUSTFLAGS", "-Dwarnings");
-    cmd.args([
-        "+nightly",
-        "check",
-        "--package",
-        "datasketches",
-        "--all-targets",
-        "--no-default-features",
-    ]);
-    for feature in features {
-        cmd.args(["--features", feature]);
-    }
-    cmd
-}
-
-fn make_format_cmd(fix: bool) -> StdCommand {
-    let mut cmd = find_command("cargo");
-    cmd.args(["+nightly", "fmt", "--all"]);
-    if !fix {
-        cmd.arg("--check");
-    }
-    cmd
-}
-
-fn make_clippy_cmd(fix: bool) -> StdCommand {
-    let mut cmd = find_command("cargo");
-    cmd.args([
-        "+nightly",
-        "clippy",
-        "--tests",
-        "--all-features",
-        "--all-targets",
-        "--workspace",
-    ]);
-    if fix {
-        cmd.args(["--allow-staged", "--allow-dirty", "--fix"]);
-    } else {
-        cmd.args(["--", "-D", "warnings"]);
-    }
-    cmd
-}
-
-fn make_docs_cmd(open: bool) -> StdCommand {
-    let mut cmd = find_command("cargo");
-    cmd.env("RUSTDOCFLAGS", "--cfg docsrs -D warnings");
-    cmd.args([
-        "+nightly",
-        "doc",
-        "--package",
-        "datasketches",
-        "--all-features",
-        "--no-deps",
-    ]);
-    if open {
-        cmd.args(["--open"]);
-    }
-    cmd
-}
-
-fn make_hawkeye_cmd(fix: bool) -> StdCommand {
-    ensure_installed("hawkeye", "hawkeye");
-    let mut cmd = find_command("hawkeye");
-    if fix {
-        cmd.args(["format"]);
-    } else {
-        cmd.args(["check"]);
-    }
-    cmd
-}
-
-fn make_typos_cmd() -> StdCommand {
-    ensure_installed("typos", "typos-cli");
-    find_command("typos")
-}
-
-fn make_taplo_cmd(fix: bool) -> StdCommand {
-    ensure_installed("taplo", "taplo-cli");
-    let mut cmd = find_command("taplo");
-    if fix {
-        cmd.args(["format"]);
-    } else {
-        cmd.args(["format", "--check"]);
-    }
-    cmd
-}
diff --git a/xtask/src/test.rs b/xtask/src/test.rs
new file mode 100644
index 0000000..3d5ab18
--- /dev/null
+++ b/xtask/src/test.rs
@@ -0,0 +1,49 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::process::Command as StdCommand;
+
+use clap::Parser;
+
+use crate::datasketches_features;
+use crate::find_command;
+use crate::run_command;
+
+#[derive(Parser)]
+pub struct CommandTest {
+    #[arg(long, help = "Run tests serially and do not capture output.")]
+    no_capture: bool,
+}
+
+impl CommandTest {
+    pub fn run(self) {
+        let features = datasketches_features();
+        run_command(make_test_cmd(self.no_capture, &features));
+    }
+}
+
+fn make_test_cmd(no_capture: bool, features: &[String]) -> StdCommand {
+    let mut cmd = find_command("cargo");
+    cmd.args(["test", "--workspace", "--no-default-features"]);
+    for feature in features {
+        cmd.args(["--features", feature]);
+    }
+    if no_capture {
+        cmd.args(["--", "--nocapture"]);
+    }
+    cmd
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to