fn create() {

    // Let user know what files and directories will be created
    // and let user answer before creating anything
    println!("Following directories and files will be created:");
    println!("\tfile      {}", TIPS.get("tipsrc").unwrap());
    println!("\tdirectory {}", TIPS.get("tips").unwrap());
    println!("\tdirectory {}", TIPS.get("data").unwrap());
    print!("Go ahead and create them ? [y/n]: ");

    match io::stdout().flush() {
        Ok(_) => (),
        Err(err) => {
            panic!("Error when trying to flush to stdout\n{}",
                   err)
        },
    };

    let mut answer = String::new();
    match io::stdin().read_line(&mut answer) {
        Ok(_) => (),
        Err(err) => {
            panic!("Error when trying to read line from stdin\n{}",
                   err)
        },
    };

    // Only proceed if user accepted, otherwise abort
    match answer.trim() {
        "y" | "Y" => (),
        _ => {
            println!("Aborted by user");
            std::process::exit(1);
        }
    };

    create_directory();
    create_tipsrc();
    create_database();
}
// Create needed file structure, tipsrc and database
Create needed file structure, tipsrc and database
Create needed file structure tipsrc and database
fn create() {
    // Let user know what files and directories will be created
    // and let user answer before creating anything
    println!("Following directories and files will be created:");
    println!("\tfile      {}", TIPS.get("tipsrc").unwrap());
    println!("\tdirectory {}", TIPS.get("tips").unwrap());
    println!("\tdirectory {}", TIPS.get("data").unwrap());
    print!("Go ahead and create them ? [y/n]: ");
    match io::stdout().flush() {
        Ok(_) => (),
        Err(err) => {
            panic!("Error when trying to flush to stdout\n{}",
                   err)
        },
    };
    let mut answer = String::new();
    match io::stdin().read_line(&mut answer) {
        Ok(_) => (),
        Err(err) => {
            panic!("Error when trying to read line from stdin\n{}",
                   err)
        },
    };
    // Only proceed if user accepted, otherwise abort
    match answer.trim() {
        "y" | "Y" => (),
        _ => {
            println!("Aborted by user");
            std::process::exit(1);
        }
    };
    create_directory();
    create_tipsrc();
    create_database();
}
fn create ( ) { // Let user know what files and directories will be created // and let user answer before creating anything println ! ( " " ) ; println ! ( " \t " TIPS get ( " " ) unwrap ( ) ) ; println ! ( " \t " TIPS get ( " " ) unwrap ( ) ) ; println ! ( " \t " TIPS get ( " " ) unwrap ( ) ) ; print ! ( " " ) ; match io :: stdout ( ) . flush ( ) { Ok ( _ ) => ( ) , Err ( err ) => { panic ! ( " \n " err ) } , } ; let mut answer = String :: new ( ) ; match io :: stdin ( ) . read_line ( & mut answer ) { Ok ( _ ) => ( ) , Err ( err ) => { panic ! ( " \n " err ) } , } ; // Only proceed if user accepted, otherwise abort match answer . trim ( ) { " " | " " => ( ) , _ => { println ! ( " " ) ; std :: process :: exit ( 1 ) ; } } ; create_directory ( ) ; create_tipsrc ( ) ; create_database ( ) ; }
Create needed file structure, tipsrc and database
Create needed file structure tipsrc and database