Skip to content

Commit 9743a5e

Browse files
aalekhpatel07NobodyXu
authored andcommitted
Use raw_command and raw_args. Refactor the name to 'over_ssh'.
Signed-off-by: Aalekh Patel <aalekh.gwpeck.7998@icloud.com>
1 parent dd64633 commit 9743a5e

File tree

3 files changed

+8
-64
lines changed

3 files changed

+8
-64
lines changed

src/command.rs

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ macro_rules! delegate {
5353
/// Primarily a way to allow `std::process::Command` to be turned directly into an `openssh::Command`.
5454
pub trait OverSsh {
5555
/// Given a session, return a command that can be executed over that session.
56-
fn with_session<'session>(&self, session: &'session Session) -> Result<crate::Command<'session>, Error>;
56+
fn over_session<'session>(&self, session: &'session Session) -> crate::Command<'session>;
5757
}
5858

5959
impl OverSsh for std::process::Command {
@@ -69,35 +69,19 @@ impl OverSsh for std::process::Command {
6969
/// .arg("-l")
7070
/// .arg("-a")
7171
/// .arg("-h")
72-
/// .with_session(&session)
72+
/// .over_session(&session)
7373
/// .output()
7474
/// .await?;
75+
///
7576
/// assert!(String::from_utf8(ls.stdout).unwrap().contains("total"));
7677
///
7778
///
7879
/// ```
79-
fn with_session<'session>(&self, session: &'session Session) -> Result<Command<'session>, Error> {
80-
let program =
81-
self
82-
.get_program()
83-
.to_str()
84-
.ok_or_else(|| Error::InvalidUtf8String(self.get_program().to_os_string()))?;
85-
86-
let args =
87-
self.
88-
get_args()
89-
.into_iter()
90-
.map(
91-
|s|
92-
s
93-
.to_str()
94-
.ok_or_else(|| Error::InvalidUtf8String(s.to_os_string()))
95-
)
96-
.collect::<Result<Vec<_>, Error>>()?;
80+
fn over_session<'session>(&self, session: &'session Session) -> Command<'session> {
9781

98-
let mut command = session.command(program);
99-
command.args(args);
100-
Ok(command)
82+
let mut command = session.raw_command(self.get_program());
83+
command.raw_args(self.get_args());
84+
command
10185
}
10286
}
10387

src/error.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ pub enum Error {
3434
#[error("the remote command could not be executed")]
3535
Remote(#[source] io::Error),
3636

37-
/// Invalid UTF-8 string when trying to
38-
/// convert a `std::ffi::OsString` to a `String`.
39-
#[error("invalid string")]
40-
InvalidUtf8String(std::ffi::OsString),
41-
4237
/// The connection to the remote host was severed.
4338
///
4439
/// Note that for the process impl, this is a best-effort error, and it _may_ instead

tests/openssh.rs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,7 @@ async fn with_session() {
300300
let mut command =
301301
std::process::Command::new("echo")
302302
.arg("foo")
303-
.with_session(&session)
304-
.expect("Expected valid utf-8 command.");
303+
.over_session(&session);
305304

306305
let child = command.output().await.unwrap();
307306
assert_eq!(child.stdout, b"foo\n");
@@ -321,40 +320,6 @@ async fn with_session() {
321320
}
322321

323322

324-
#[tokio::test]
325-
#[cfg_attr(not(ci), ignore)]
326-
async fn with_session_err() {
327-
328-
for session in connects().await {
329-
let bad_string = OsStr::from_bytes(b"foo\xFF");
330-
let command =
331-
std::process::Command::new("echo")
332-
.arg(bad_string)
333-
.with_session(&session);
334-
335-
let expected_error = openssh::Error::InvalidUtf8String(bad_string.to_owned());
336-
assert!(command.is_err());
337-
let err = command.unwrap_err();
338-
assert_eq!(err.to_string(), expected_error.to_string());
339-
340-
// let child = command.output().await.unwrap();
341-
// assert_eq!(child.stdout, b"foo\n");
342-
343-
// let child = session
344-
// .command("echo")
345-
// .arg("foo")
346-
// .raw_arg(">")
347-
// .arg("/dev/stderr")
348-
// .output()
349-
// .await
350-
// .unwrap();
351-
// assert!(child.stdout.is_empty());
352-
353-
session.close().await.unwrap();
354-
}
355-
}
356-
357-
358323
#[tokio::test]
359324
#[cfg_attr(not(ci), ignore)]
360325
async fn shell() {

0 commit comments

Comments
 (0)