-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add commands function #64
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,12 +2,14 @@ use std::{ffi::OsStr, io, process::Command}; | |||||
|
||||||
use crate::{CommandExt, IntoResult}; | ||||||
|
||||||
pub fn command<T: AsRef<OsStr>>(path: T) -> Command { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The signature here could be
Suggested change
Note that |
||||||
let mut cmd = Command::new("uiopen"); | ||||||
cmd.arg("--url").arg(path.as_ref()); | ||||||
cmd | ||||||
} | ||||||
|
||||||
pub fn that<T: AsRef<OsStr>>(path: T) -> io::Result<()> { | ||||||
Command::new("uiopen") | ||||||
.arg("--url") | ||||||
.arg(path.as_ref()) | ||||||
.status_without_output() | ||||||
.into_result() | ||||||
command(path).status_without_output().into_result() | ||||||
} | ||||||
|
||||||
pub fn with<T: AsRef<OsStr>>(path: T, app: impl Into<String>) -> io::Result<()> { | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,12 @@ | |
//! open::with("http://rust-lang.org", "firefox").unwrap(); | ||
//! ``` | ||
//! | ||
//! Or obtain the command without running it. | ||
//! | ||
//! ```no_run | ||
//! let cmd = open::command("http://rust-lang.org"); | ||
//! ``` | ||
//! | ||
//! # Notes | ||
//! | ||
//! ## Nonblocking operation | ||
|
@@ -131,6 +137,18 @@ pub fn with<T: AsRef<OsStr>>(path: T, app: impl Into<String>) -> io::Result<()> | |
os::with(path, app) | ||
} | ||
|
||
/// Get command that opens path with the default application. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should be mentioned that this is a 'no-run' sibling of |
||
/// | ||
/// # Examples | ||
/// | ||
/// ```no_run | ||
/// let path = "http://rust-lang.org"; | ||
/// let cmd = open::command(path); | ||
/// ``` | ||
pub fn command<'a, T: AsRef<OsStr>>(path: T) -> Command { | ||
os::command(path) | ||
} | ||
|
||
/// Open path with the default application in a new thread. | ||
/// | ||
/// See documentation of [`that()`] for more details. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this
CommandExt
method should be split into two, so the configuration of IO channels is separate from executing it.Thus, future invocations would look more like this: