##// END OF EJS Templates
rust-chg: add interface to chdir the server
Yuya Nishihara -
r40014:045ea159 default
parent child Browse files
Show More
@@ -1,51 +1,64 b''
1 1 // Copyright 2018 Yuya Nishihara <yuya@tcha.org>
2 2 //
3 3 // This software may be used and distributed according to the terms of the
4 4 // GNU General Public License version 2 or any later version.
5 5
6 6 //! cHg extensions to command server client.
7 7
8 8 use std::ffi::OsStr;
9 use std::os::unix::ffi::OsStrExt;
9 10 use std::os::unix::io::AsRawFd;
11 use std::path::Path;
10 12 use tokio_hglib::{Client, Connection};
13 use tokio_hglib::protocol::OneShotRequest;
11 14
12 15 use super::attachio::AttachIo;
13 16 use super::message;
14 17 use super::runcommand::ChgRunCommand;
15 18 use super::uihandler::SystemHandler;
16 19
17 20 pub trait ChgClientExt<C>
18 21 where C: Connection + AsRawFd,
19 22 {
20 23 /// Attaches the client file descriptors to the server.
21 24 fn attach_io<I, O, E>(self, stdin: I, stdout: O, stderr: E) -> AttachIo<C, I, O, E>
22 25 where I: AsRawFd,
23 26 O: AsRawFd,
24 27 E: AsRawFd;
25 28
29 /// Changes the working directory of the server.
30 fn set_current_dir<P>(self, dir: P) -> OneShotRequest<C>
31 where P: AsRef<Path>;
32
26 33 /// Runs the specified Mercurial command with cHg extension.
27 34 fn run_command_chg<I, P, H>(self, handler: H, args: I) -> ChgRunCommand<C, H>
28 35 where I: IntoIterator<Item = P>,
29 36 P: AsRef<OsStr>,
30 37 H: SystemHandler;
31 38 }
32 39
33 40 impl<C> ChgClientExt<C> for Client<C>
34 41 where C: Connection + AsRawFd,
35 42 {
36 43 fn attach_io<I, O, E>(self, stdin: I, stdout: O, stderr: E) -> AttachIo<C, I, O, E>
37 44 where I: AsRawFd,
38 45 O: AsRawFd,
39 46 E: AsRawFd,
40 47 {
41 48 AttachIo::with_client(self, stdin, stdout, Some(stderr))
42 49 }
43 50
51 fn set_current_dir<P>(self, dir: P) -> OneShotRequest<C>
52 where P: AsRef<Path>,
53 {
54 OneShotRequest::start_with_args(self, b"chdir", dir.as_ref().as_os_str().as_bytes())
55 }
56
44 57 fn run_command_chg<I, P, H>(self, handler: H, args: I) -> ChgRunCommand<C, H>
45 58 where I: IntoIterator<Item = P>,
46 59 P: AsRef<OsStr>,
47 60 H: SystemHandler,
48 61 {
49 62 ChgRunCommand::with_client(self, handler, message::pack_args_os(args))
50 63 }
51 64 }
General Comments 0
You need to be logged in to leave comments. Login now