Skip to main content

classify

Function classify 

Source
pub fn classify(
    output: &CommandOutput,
    command: &str,
    patterns: &[Pattern],
) -> Classification
Expand description

Classify command output using patterns and automatic category detection.

This is the main entry point for output classification. It analyzes the command’s exit code, output size, and applies pattern matching to determine the appropriate presentation strategy.

§Algorithm

  1. Failure path (exit_code ≠ 0): Apply failure pattern or smart truncation
  2. Small success (output ≤ 4KB): Pass through verbatim
  3. Pattern match: Extract summary using success pattern
  4. Category fallback: Use command category to determine behavior

§Arguments

  • output - The command’s exit code, stdout, and stderr
  • command - The command string (used for pattern matching and category detection)
  • patterns - List of patterns to try (typically pattern::builtins + user patterns)

§Returns

A Classification indicating how to present the output.

§Examples

use double_o::{classify, CommandOutput};
use double_o::pattern::builtins;

let output = CommandOutput {
    stdout: b"test result: ok. 5 passed; 0 failed; finished in 0.3s".to_vec(),
    stderr: Vec::new(),
    exit_code: 0,
};
let patterns = builtins();
let result = classify(&output, "cargo test", patterns);