pub fn from_file(filepath: &Path) -> Result<Conf, ConfError> {
        let data = fs::read_to_string(filepath)?;
        let root: Value = data.parse::<Value>()?;
        // reading verbs
        let mut verbs: Vec<VerbConf> = vec![];
        if let Some(Value::Array(verbs_value)) = &root.get("verbs") {
            for verb_value in verbs_value.iter() {
                let invocation = match string_field(verb_value, "invocation") {
                    Some(s) => s,
                    None => {
                        eprintln!("Invalid [[verbs]] entry in configuration");
                        eprintln!("Missing invocation");
                        continue;
                    }
                };
                let key = string_field(verb_value, "key").map(
                    |s| verb_conf::parse_key(&s)
                ).transpose()?;
                let execution = match string_field(verb_value, "execution") {
                    Some(s) => s,
                    None => {
                        eprintln!("Invalid [[verbs]] entry in configuration");
                        eprintln!("Missing execution");
                        continue;
                    }
                };
                let from_shell = bool_field(verb_value, "from_shell");
                let leave_broot = bool_field(verb_value, "leave_broot");
                if leave_broot == Some(false) && from_shell == Some(true) {
                    eprintln!("Invalid [[verbs]] entry in configuration");
                    eprintln!(
                        "You can't simultaneously have leave_broot=false and from_shell=true"
                    );
                    continue;
                }
                verbs.push(VerbConf {
                    invocation,
                    execution,
                    key,
                    shortcut: string_field(verb_value, "shortcut"),
                    description: string_field(verb_value, "description"),
                    from_shell,
                    leave_broot,
                    confirm: bool_field(verb_value, "confirm"),
                });
            }
        }
        // reading the skin
        let mut skin = HashMap::new();
        if let Some(Value::Table(entries_tbl)) = &root.get("skin") {
            for (k, v) in entries_tbl.iter() {
                if let Some(s) = v.as_str() {
                    match skin_conf::parse_object_style(s) {
                        Ok(ske) => {
                            skin.insert(k.to_string(), ske);
                        }
                        Err(e) => {
                            eprintln!("{}", e);
                        }
                    }
                }
            }
        }

        Ok(Conf { verbs, skin })
    }
/// read the configuration from a given path. Assume it exists.
/// stderr is supposed to be a valid solution for displaying errors
/// (i.e. this function is called before or after the terminal alternation)
read the configuration from a given path. Assume it exists.
stderr is supposed to be a valid solution for displaying errors
read the configuration from a given path . Assume it exists . stderr is supposed to be a valid solution for displaying errors
pub fn from_file(filepath: &Path) -> Result<Conf, ConfError> {
        let data = fs::read_to_string(filepath)?;
        let root: Value = data.parse::<Value>()?;
        // reading verbs
        let mut verbs: Vec<VerbConf> = vec![];
        if let Some(Value::Array(verbs_value)) = &root.get("verbs") {
            for verb_value in verbs_value.iter() {
                let invocation = match string_field(verb_value, "invocation") {
                    Some(s) => s,
                    None => {
                        eprintln!("Invalid [[verbs]] entry in configuration");
                        eprintln!("Missing invocation");
                        continue;
                    }
                };
                let key = string_field(verb_value, "key").map(
                    |s| verb_conf::parse_key(&s)
                ).transpose()?;
                let execution = match string_field(verb_value, "execution") {
                    Some(s) => s,
                    None => {
                        eprintln!("Invalid [[verbs]] entry in configuration");
                        eprintln!("Missing execution");
                        continue;
                    }
                };
                let from_shell = bool_field(verb_value, "from_shell");
                let leave_broot = bool_field(verb_value, "leave_broot");
                if leave_broot == Some(false) && from_shell == Some(true) {
                    eprintln!("Invalid [[verbs]] entry in configuration");
                    eprintln!(
                        "You can't simultaneously have leave_broot=false and from_shell=true"
                    );
                    continue;
                }
                verbs.push(VerbConf {
                    invocation,
                    execution,
                    key,
                    shortcut: string_field(verb_value, "shortcut"),
                    description: string_field(verb_value, "description"),
                    from_shell,
                    leave_broot,
                    confirm: bool_field(verb_value, "confirm"),
                });
            }
        }
        // reading the skin
        let mut skin = HashMap::new();
        if let Some(Value::Table(entries_tbl)) = &root.get("skin") {
            for (k, v) in entries_tbl.iter() {
                if let Some(s) = v.as_str() {
                    match skin_conf::parse_object_style(s) {
                        Ok(ske) => {
                            skin.insert(k.to_string(), ske);
                        }
                        Err(e) => {
                            eprintln!("{}", e);
                        }
                    }
                }
            }
        }
        Ok(Conf { verbs, skin })
    }
pub fn from_file ( filepath : & Path ) -> Result < Conf , ConfError > { let data = fs :: read_to_string ( filepath ) ? ; let root : Value = data . parse :: < Value > ( ) ? ; // reading verbs let mut verbs : Vec < VerbConf > = vec ! [ ] ; if let Some ( Value :: Array ( verbs_value ) ) = & root . get ( " " ) { for verb_value in verbs_value . iter ( ) { let invocation = match string_field ( verb_value , " " ) { Some ( s ) => s , None => { eprintln ! ( " " ) ; eprintln ! ( " " ) ; continue ; } } ; let key = string_field ( verb_value , " " ) . map ( | s | verb_conf :: parse_key ( & s ) ) . transpose ( ) ? ; let execution = match string_field ( verb_value , " " ) { Some ( s ) => s , None => { eprintln ! ( " " ) ; eprintln ! ( " " ) ; continue ; } } ; let from_shell = bool_field ( verb_value , " " ) ; let leave_broot = bool_field ( verb_value , " " ) ; if leave_broot == Some ( false ) && from_shell == Some ( true ) { eprintln ! ( " " ) ; eprintln ! ( " " ) ; continue ; } verbs . push ( VerbConf { invocation , execution , key , shortcut : string_field ( verb_value , " " ) , description : string_field ( verb_value , " " ) , from_shell , leave_broot , confirm : bool_field ( verb_value , " " ) , } ) ; } } // reading the skin let mut skin = HashMap :: new ( ) ; if let Some ( Value :: Table ( entries_tbl ) ) = & root . get ( " " ) { for ( k , v ) in entries_tbl . iter ( ) { if let Some ( s ) = v . as_str ( ) { match skin_conf :: parse_object_style ( s ) { Ok ( ske ) => { skin . insert ( k . to_string ( ) , ske ) ; } Err ( e ) => { eprintln ! ( " " e ) ; } } } } } Ok ( Conf { verbs , skin } ) }
read the configuration from a given path.
read the configuration from a given path .
filepath
&Path
filepath
&Path