fixed a panic when opening a file with an unconfigured extension

This commit is contained in:
Valerie Wolfe 2021-11-25 12:53:36 -05:00
parent a270d08c47
commit 17a05cf2c5
3 changed files with 13 additions and 11 deletions

View file

@ -1,10 +1,10 @@
[package]
name = "open"
version = "0.4.0"
version = "0.5.0"
authors = ["Valerie Wolfe <sleeplessval@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
configparser = "2.0.1"
configparser = "3.0.0"

View file

@ -86,13 +86,15 @@ impl Config {
}
return output;
}
pub fn getbool(&self, section: &str, key: &str) -> Result<Option<bool>, String> {
let mut output = Ok(None);
pub fn getbool(&self, section: &str, key: &str) -> Option<bool> {
let mut output = None;
if self.local.is_some() {
output = self.local.as_ref().unwrap().getbool(section, key);
let i_out = self.local.as_ref().unwrap().getbool(section, key);
output = i_out.unwrap_or(None);
}
if output.clone().ok().is_none() && self.global.is_some() {
output = self.global.as_ref().unwrap().getbool(section, key);
if output.is_none() && self.global.is_some() {
let i_out = self.global.as_ref().unwrap().getbool(section, key);
output = i_out.unwrap_or(None);
}
return output;
}
@ -105,7 +107,7 @@ impl Config {
ini = self.global.clone().unwrap();
}
ini.set(section, key, Some(value));
if local{
if local {
self.local = Some(ini);
} else {
self.global = Some(ini);

View file

@ -22,7 +22,7 @@ fn main() {
match arg.as_str() {
"-h" |
"--help" => {
println!("open v0.4.0
println!("open v0.5.0
Valerie Wolfe <sleeplessval@gmail.com>
A Linux implementation of the \"open\" command on Mac OS written in Rust and easily configurable.
@ -106,7 +106,7 @@ FLAGS:
let i_exe = config.get(ext, "command");
if i_exe.is_none() {
let use_editor = config.getbool("open", "use_editor");
if use_editor.is_ok() && use_editor.ok().unwrap().unwrap() {
if use_editor.unwrap_or(false) {
let i_editor = var("EDITOR");
if i_editor.is_err() {
println!("open: encountered an error trying to access $EDITOR");
@ -143,7 +143,7 @@ FLAGS:
command.args(param)
.current_dir(dir);
let is_sh = config.getbool(ext, "shell").ok().unwrap_or(Some(false)).unwrap_or(false);
let is_sh = config.getbool(ext, "shell").unwrap_or(false);
if is_sh {
command.stdout(Stdio::inherit())
.stderr(Stdio::inherit())