Function flood_tide_gen::do_gen_src

source ·
pub fn do_gen_src<F>(
    pas: Pasc,
    in_f: &str,
    out_f_help: Option<&str>,
    out_f_match: Option<&str>,
    f: F
) -> Result<()>where
    F: Fn(&OptStr) -> Option<FixupType>,
Expand description

read input file and generate out help source, match source file.

Examples

Simple Example

use flood_tide_gen::{do_gen_src, FixupType, MetaType, Pasc};

fn do_gen_cmd() -> anyhow::Result<()> {
    do_gen_src(Pasc::Void, "xtask/aki-gsub-cmd.txt",
        Some("src/conf/cmd.help.rs.txt"), Some("src/conf/cmd.match.rs.txt"),
        |opt_str| {
            let tup = match opt_str.lon_or_sho() {
                "color" => (false, false, MetaType::Other("opt_color_when".into())),
                "exp" => (false, true, opt_str.meta_type.clone()),
                "format" => (false, true, opt_str.meta_type.clone()),
                _ => return None,
            };
            Some(FixupType::from_tuple(tup))
        },
    )?;
    Ok(())
}

Fixup Type Example

use flood_tide_gen::{do_gen_src, FixupType, MetaType, Pasc, OptStr};

fn do_gen_cmd() -> anyhow::Result<()> {
    do_gen_src(Pasc::Void, "xtask/aki-gsub-cmd.txt",
        Some("src/conf/cmd.help.rs.txt"), Some("src/conf/cmd.match.rs.txt"),
        do_fix_type
    )?;
    Ok(())
}
pub fn do_fix_type(opt_str: &OptStr) -> Option<FixupType> {
    let tup = match opt_str.lon_or_sho() {
        "color" => (false, false, MetaType::Other("opt_color_when".into())),
        "exp" => (false, true, opt_str.meta_type.clone()),
        "format" => (false, true, opt_str.meta_type.clone()),
        _ => return None,
    };
    Some(FixupType::from_tuple(tup))
}