forked from InfoshockTech/xcrab
Use expect() instead of try
This commit is contained in:
parent
4a3b1c169d
commit
2aac4731dd
|
@ -13,7 +13,6 @@
|
||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::Result;
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
@ -28,12 +27,17 @@ pub struct XcrabMsgConfig {
|
||||||
pub socket_path: PathBuf,
|
pub socket_path: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_file() -> Result<XcrabConfig> {
|
pub fn load_file() -> XcrabConfig {
|
||||||
let home_dir = std::env::var("HOME")?;
|
let home_dir = std::env::var("HOME").expect("Error: $HOME variable was not set");
|
||||||
|
|
||||||
let contents = std::fs::read_to_string(format!("{}/.config/xcrab/config.toml", home_dir))?;
|
let contents = std::fs::read_to_string(format!("{}/.config/xcrab/config.toml", home_dir))
|
||||||
|
.expect(&format!(
|
||||||
|
"Error: file {}/.config/xcrab/config.toml was not found",
|
||||||
|
home_dir
|
||||||
|
));
|
||||||
|
|
||||||
let config: XcrabConfig = toml::from_str(&contents)?;
|
let config: XcrabConfig = toml::from_str(&contents)
|
||||||
|
.expect("Error: config file was not parseable. Is it properly formatted?");
|
||||||
|
|
||||||
Ok(config)
|
config
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
let msg = std::env::args().skip(1).collect::<Vec<String>>().join(" ");
|
let msg = std::env::args().skip(1).collect::<Vec<String>>().join(" ");
|
||||||
|
|
||||||
let conf = config::load_file()?;
|
let conf = config::load_file();
|
||||||
|
|
||||||
let path = conf.msg.expect("xcrab-msg not configured!").socket_path;
|
let path = conf.msg.expect("xcrab-msg not configured!").socket_path;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue