use std::io::Write;
use std::path::Path;
use caexfer::{Format, Options, Result};
use super::args::Args;
use super::json::quote;
pub(super) fn emit(value: &str) -> Result<()> {
let mut stdout = std::io::stdout().lock();
writeln!(stdout, "{value}")?;
Ok(())
}
pub(super) fn path_json(path: &Path) -> String {
quote(&path.to_string_lossy())
}
fn format_of(args: &Args) -> Result<Format> {
args.from
.as_deref()
.map_or_else(|| Format::from_input_path(&args.paths[0]), Format::parse)
}
pub(super) fn conversion_options(args: &Args) -> Result<Options> {
let format = format_of(args)?;
Ok(Options {
input_format: Some(format),
mesh: args.mesh.clone(),
assume_basic_frame: args.accept_basic_frame,
subcase: args.subcase,
step: args.step,
max_bytes: args.max_bytes.unwrap_or(Options::default().max_bytes),
msh_version: args.msh_version,
match_grid: args.match_grid.clone(),
infill_shape: args.infill_shape,
infill_unit_size: args.infill_unit_size,
surface: args.surface,
gmsh: args.gmsh.clone(),
smooth_iterations: args.smooth_iterations.unwrap_or(0),
zero_missing_rotations: args.accept_zero_rotations,
accept_omissions: args.accept_omissions || args.accept_all,
accept_synthetic_zero: args.accept_synthetic_zero || args.accept_all,
mesh_output: args.mesh_out.clone(),
strict: args.strict,
accept_all: args.accept_all,
})
}