@@ -53,38 +53,127 @@ macro_rules! delegate {
53
53
/// Primarily a way to allow `std::process::Command` to be turned directly into an `openssh::Command`.
54
54
pub trait OverSsh {
55
55
/// Given a session, return a command that can be executed over that session.
56
+ ///
57
+ /// **Note**: The command to be executed on the remote machine does not include
58
+ /// any environment variables or the current directory. They must be
59
+ /// set explicitly, if desired.
56
60
fn over_session < ' session > ( & self , session : & ' session Session ) -> crate :: Command < ' session > ;
57
61
}
58
62
59
63
impl OverSsh for std:: process:: Command {
60
64
/// Given a session, convert a `std::process::Command` into an `openssh::Command`
61
65
/// that can be executed over that session.
66
+ /// **Note**: The command to be executed on the remote machine does not include
67
+ /// any environment variables or the current directory. They must be
68
+ /// set explicitly, if desired.
62
69
/// ```no_run
63
- /// use std::process::Command;
64
- /// use openssh::{Session, KnownHosts, OverSsh};
65
-
66
- /// let session = Session::connect_mux("me@ssh.example.com" , KnownHosts::Strict).await? ;
67
- /// let ls =
68
- /// Command::new("ls")
69
- /// .arg("-l")
70
- /// .arg("-a ")
71
- /// .arg("-h ")
72
- /// .over_session(&session )
73
- /// .output( )
74
- /// .await?;
75
- ///
76
- /// assert!(String::from_utf8(ls.stdout).unwrap().contains("total")) ;
70
+ /// # #[tokio::main(flavor = "current_thread")]
71
+ /// async fn main() -> Result<(), Box<dyn std::error::Error>> {
72
+ /// use std::process::Command;
73
+ /// use openssh::{Session , KnownHosts, OverSsh} ;
74
+
75
+ /// let session = Session::connect_mux("me@ssh.example.com", KnownHosts::Strict).await?;
76
+ /// let ls =
77
+ /// Command::new("ls ")
78
+ /// .arg("-l ")
79
+ /// .arg("-a" )
80
+ /// .arg("-h" )
81
+ /// .over_session(&session)
82
+ /// .output()
83
+ /// .await? ;
77
84
///
85
+ /// assert!(String::from_utf8(ls.stdout).unwrap().contains("total"));
86
+ /// # Ok(())
87
+ /// }
78
88
///
79
89
/// ```
80
90
fn over_session < ' session > ( & self , session : & ' session Session ) -> Command < ' session > {
81
-
82
- let mut command = session. raw_command ( self . get_program ( ) ) ;
91
+ let mut command = session. command ( self . get_program ( ) . to_string_lossy ( ) ) ;
83
92
command. raw_args ( self . get_args ( ) ) ;
84
93
command
85
94
}
86
95
}
87
96
97
+
98
+ impl OverSsh for tokio:: process:: Command {
99
+ /// Given a session, convert a `tokio::process::Command` into an `openssh::Command`
100
+ /// that can be executed over that session.
101
+ ///
102
+ /// **Note**: The command to be executed on the remote machine does not include
103
+ /// any environment variables or the current directory. They must be
104
+ /// set explicitly, if desired.
105
+ /// ```no_run
106
+ /// # #[tokio::main(flavor = "current_thread")]
107
+ /// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
108
+ /// use tokio::process::Command;
109
+ /// use openssh::{Session, KnownHosts, OverSsh};
110
+
111
+ /// let session = Session::connect_mux("me@ssh.example.com", KnownHosts::Strict).await?;
112
+ /// let ls =
113
+ /// Command::new("ls")
114
+ /// .arg("-l")
115
+ /// .arg("-a")
116
+ /// .arg("-h")
117
+ /// .over_session(&session)
118
+ /// .output()
119
+ /// .await?;
120
+ ///
121
+ /// assert!(String::from_utf8(ls.stdout).unwrap().contains("total"));
122
+ /// # Ok(())
123
+ /// # }
124
+ ///
125
+ /// ```
126
+ fn over_session < ' session > ( & self , session : & ' session Session ) -> Command < ' session > {
127
+ self . as_std ( ) . over_session ( session)
128
+ }
129
+ }
130
+
131
+
132
+ impl < S > OverSsh for & S
133
+ where
134
+ S : OverSsh
135
+ {
136
+ fn over_session < ' session > ( & self , session : & ' session Session ) -> Command < ' session > {
137
+ <S as OverSsh >:: over_session ( self , session)
138
+ }
139
+ }
140
+
141
+ impl < S > OverSsh for & mut S
142
+ where
143
+ S : OverSsh
144
+ {
145
+ fn over_session < ' session > ( & self , session : & ' session Session ) -> Command < ' session > {
146
+ <S as OverSsh >:: over_session ( self , session)
147
+ }
148
+ }
149
+
150
+ impl < S > OverSsh for Box < S >
151
+ where
152
+ S : OverSsh
153
+ {
154
+ fn over_session < ' session > ( & self , session : & ' session Session ) -> Command < ' session > {
155
+ <S as OverSsh >:: over_session ( self , session)
156
+ }
157
+ }
158
+
159
+ impl < S > OverSsh for std:: rc:: Rc < S >
160
+ where
161
+ S : OverSsh
162
+ {
163
+ fn over_session < ' session > ( & self , session : & ' session Session ) -> Command < ' session > {
164
+ <S as OverSsh >:: over_session ( self , session)
165
+ }
166
+ }
167
+
168
+ impl < S > OverSsh for std:: sync:: Arc < S >
169
+ where
170
+ S : OverSsh
171
+ {
172
+ fn over_session < ' session > ( & self , session : & ' session Session ) -> Command < ' session > {
173
+ <S as OverSsh >:: over_session ( self , session)
174
+ }
175
+ }
176
+
88
177
/// A remote process builder, providing fine-grained control over how a new remote process should
89
178
/// be spawned.
90
179
///
0 commit comments