main
John Lauer Publish 0.1.26 0b71841
"""Integrate only the new section command into the chosen current AI Flow source.
Fail closed when the expected clap/match anchors have changed. Does not replace
main.rs with the development snapshot or remove any existing commands.
"""
import argparse
from pathlib import Path
p=argparse.ArgumentParser();p.add_argument('main',type=Path);a=p.parse_args();s=a.main.read_text()
if 'mod silkscreen_sections;' not in s:
 anchor='use std::collections::BTreeMap;'
 if s.count(anchor)!=1:raise SystemExit('Current import anchor changed; integrate the module explicitly')
 s=s.replace(anchor,'mod silkscreen_sections;\n'+anchor,1)
if 'SilkscreenSections {' in s:raise SystemExit('Section command already exists; review its implementation instead of duplicating it')
if s.count('enum Cmd {')!=1 or s.count('match &cli.cmd {')!=1:raise SystemExit('Current CLI anchors changed; integrate explicitly')
s=s.replace('enum Cmd {','enum Cmd {\n    SilkscreenSections { #[arg(long)] input: PathBuf, #[arg(long)] out: PathBuf },',1)
arm='''
        Cmd::SilkscreenSections { input, out } => {
            thread(&cli); let _r=load_run(&cli);
            let data:serde_json::Value=serde_json::from_slice(&std::fs::read(input).unwrap_or_else(|e|err(&e.to_string(), &[]))).unwrap_or_else(|e|err(&e.to_string(), &[]));
            let result=silkscreen_sections::solve(&data).unwrap_or_else(|e|err(&e,&[]));
            std::fs::write(out,serde_json::to_vec_pretty(&result).unwrap()).unwrap_or_else(|e|err(&e.to_string(), &[]));
            if !result["unresolved"].as_array().unwrap().is_empty(){err("Documentation sections remain unresolved", &["Keep rows together; try shorter line layouts or other interior regions before edge fallback.".into()]);}
            let fallbacks=result["sections"].as_array().unwrap().iter().filter(|s|s["edgeFallback"]==true).count();
            ok(&format!("Native Rust placed {} documentation labels; {fallbacks} edge fallbacks",result["placements"].as_array().unwrap().len()), &["Prefer open board interior for a verified board description and left-aligned service blocks. Physical pin/contact labels stay local. Follow docs/silkscreen-priority-pass.md; inspect font sizes, edge fallbacks, native DRC and both EDA views.".into()]);
        }
'''
s=s.replace('match &cli.cmd {','match &cli.cmd {'+arm,1);a.main.write_text(s);print('Added native Rust section command without replacing existing commands')