Module cli

Module cli 

Source
Expand description

CLI integration helpers for multiio.

This module keeps CLI-related types intentionally lightweight so callers can integrate with any argument parser (clap/sarge/argh/…).

§Token conventions

multiio intentionally supports a small set of conventional “special” tokens for CLI ergonomics:

  • Inputs:
    • - or stdin => stdin
    • =<content> => inline content (in-memory input)
    • @<path> => force treating the value as a file path (useful for disambiguating reserved tokens)
  • Outputs:
    • - or stdout => stdout
    • stderr => stderr
    • @<path> => force treating the value as a file path (e.g. @stderr)

§Example

use multiio::{default_registry, MultiioBuilder};
use multiio::cli::{InputArgs, OutputArgs};

fn run(inputs: Vec<String>, outputs: Vec<String>) -> Result<(), Box<dyn std::error::Error>> {
    let input = InputArgs::from(inputs);
    let output = OutputArgs::from(outputs);

    let engine = MultiioBuilder::new(default_registry())
        .with_input_args(&input)
        .with_output_args(&output)
        .build()?;

    let values: Vec<serde_json::Value> = engine.read_all()?;
    engine.write_all(&values)?;
    Ok(())
}

Structs§

InputArgs
Common input arguments for CLI applications.
OutputArgs

Functions§

infer_format_from_path
Infer format from file extension.
parse_format
Parse a format string into a FormatKind.