fn add_tip(source: Source) {

    // Write the template to file, and then open it
    write_template(source);
    crate::open::editor(&CONFIG.tmp_file);

    // Read the contents of tmp file and remove the tmp file
    let contents = crate::helpers::read_to_string(&CONFIG.tmp_file);
    crate::helpers::remove_file(&CONFIG.tmp_file);

    // if contents do not differ from template then abort
    if &contents[0..TIP.template.len()] == TIP.template {
        println!("Aborting. Contents no different from template.");
        process::exit(1)
    }

    // Create a new Tip from the read data and add it to tips
    let mut tip: crate::tip::Tip = create(contents);
    tip.metadata.id = crate::tips::Tips::next_id();
    crate::tips::Tips::add(tip);
}
// Help function to add a new Tip
Help function to add a new Tip
Help function to add a new Tip
fn add_tip(source: Source) {
    // Write the template to file, and then open it
    write_template(source);
    crate::open::editor(&CONFIG.tmp_file);
    // Read the contents of tmp file and remove the tmp file
    let contents = crate::helpers::read_to_string(&CONFIG.tmp_file);
    crate::helpers::remove_file(&CONFIG.tmp_file);
    // if contents do not differ from template then abort
    if &contents[0..TIP.template.len()] == TIP.template {
        println!("Aborting. Contents no different from template.");
        process::exit(1)
    }
    // Create a new Tip from the read data and add it to tips
    let mut tip: crate::tip::Tip = create(contents);
    tip.metadata.id = crate::tips::Tips::next_id();
    crate::tips::Tips::add(tip);
}
fn add_tip ( source : Source ) { // Write the template to file, and then open it write_template ( source ) ; crate :: open :: editor ( & CONFIG . tmp_file ) ; // Read the contents of tmp file and remove the tmp file let contents = crate :: helpers :: read_to_string ( & CONFIG . tmp_file ) ; crate :: helpers :: remove_file ( & CONFIG . tmp_file ) ; // if contents do not differ from template then abort if & contents [ 0 .. TIP . template . len ( ) ] == TIP . template { println ! ( " " ) ; process :: exit ( 1 ) } // Create a new Tip from the read data and add it to tips let mut tip : crate :: tip :: Tip = create ( contents ) ; tip . metadata . id = crate :: tips :: Tips :: next_id ( ) ; crate :: tips :: Tips :: add ( tip ) ; }
Help function to add a new Tip
Help function to add a new Tip
source
Source
source
Source