Abstract URL opening in utility, use Url instances

This commit is contained in:
timvisee 2018-03-18 21:01:54 +01:00
parent c2611049df
commit a4aa1b93e5
No known key found for this signature in database
GPG key ID: 109CBA0BF74036C2
5 changed files with 32 additions and 11 deletions

View file

@ -1,4 +1,9 @@
use std::process::exit;
extern crate open;
use std::io::Error as IoError;
use std::process::{exit, ExitStatus};
use ffsend_api::url::Url;
/// Quit the application with an error code,
/// and print the given error message.
@ -9,3 +14,15 @@ pub fn quit_error<S: AsRef<str>>(err: S) -> ! {
// Quit
exit(1);
}
/// Open the given URL in the users default browser.
/// The browsers exit statis is returned.
pub fn open_url(url: Url) -> Result<ExitStatus, IoError> {
open_path(url.as_str())
}
/// Open the given path or URL using the program configured on the system.
/// The program exit statis is returned.
pub fn open_path(path: &str) -> Result<ExitStatus, IoError> {
open::that(path)
}