ctb_formats_x86/
cli.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2/*
3This file is part of Collective Toolbox, a database and document workspace and utilities.
4Copyright (C) 2026 Collective Toolbox Developers
5Contact: info@collectivetoolbox.com
6
7This program is free software: you can redistribute it and/or modify it under
8the terms of the GNU Affero General Public License as published by the Free
9Software Foundation, either version 3 of the License, or (at your option) any
10later version.
11
12This program is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
15
16You should have received a copy of the GNU Affero General Public License along
17with this program.  If not, see <https://www.gnu.org/licenses/>.
18*/
19
20//! CLI execution helpers for x86 instruction sets extraction.
21
22#[allow(
23    unused_imports,
24    clippy::wildcard_imports,
25    reason = "Standard workspace module prelude"
26)]
27use crate::utilities::*;
28
29use anyhow::Context;
30use std::path::Path;
31
32pub fn instruction_sets(path: &Path) -> Result<ToolResult> {
33    let data = std::fs::read(path)
34        .with_context(|| format!("Failed to read file: {}", path.display()))?;
35    let sets = crate::extract_instruction_sets(&data)?;
36    let mut output = sets.join("\n");
37    if !output.is_empty() {
38        output.push('\n');
39    }
40    Ok(ToolResult::immediate_ok(output.into_bytes()))
41}
42
43#[cfg(test)]
44#[allow(
45    clippy::panic,
46    clippy::expect_used,
47    clippy::unwrap_used,
48    clippy::unwrap_in_result,
49    clippy::panic_in_result_fn,
50    clippy::indexing_slicing,
51    clippy::arithmetic_side_effects,
52    reason = "Standard repository test boilerplate"
53)]
54mod tests {
55    use super::*;
56
57    #[crate::ctb_test]
58    fn test_x86_instruction_sets_command() {
59        let temp_dir = tempfile::tempdir().unwrap();
60        let sample_file = temp_dir.path().join("dummy.bin");
61        std::fs::write(&sample_file, b"not a binary").unwrap();
62
63        assert!(super::instruction_sets(&sample_file).is_err());
64    }
65}