Show More
@@ -1,59 +1,59 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 | extern crate chg; |
|
7 | 7 | extern crate futures; |
|
8 | 8 | extern crate tokio; |
|
9 | 9 | extern crate tokio_hglib; |
|
10 | 10 | |
|
11 | 11 | use chg::{ChgClientExt, ChgUiHandler}; |
|
12 | 12 | use chg::locator; |
|
13 | 13 | use chg::procutil; |
|
14 | 14 | use futures::sync::oneshot; |
|
15 | 15 | use std::env; |
|
16 | 16 | use std::io; |
|
17 | 17 | use std::process; |
|
18 | 18 | use tokio::prelude::*; |
|
19 | 19 | use tokio_hglib::UnixClient; |
|
20 | 20 | |
|
21 | 21 | fn main() { |
|
22 | 22 | let code = run().unwrap_or_else(|err| { |
|
23 |
|
|
|
23 | writeln!(io::stderr(), "chg: abort: {}", err).unwrap_or(()); | |
|
24 | 24 | 255 |
|
25 | 25 | }); |
|
26 | 26 | process::exit(code); |
|
27 | 27 | } |
|
28 | 28 | |
|
29 | 29 | fn run() -> io::Result<i32> { |
|
30 | 30 | let current_dir = env::current_dir()?; |
|
31 | 31 | let sock_path = locator::prepare_server_socket_path()?; |
|
32 | 32 | let handler = ChgUiHandler::new(); |
|
33 | 33 | let (result_tx, result_rx) = oneshot::channel(); |
|
34 | 34 | let fut = UnixClient::connect(sock_path) |
|
35 | 35 | .and_then(|client| { |
|
36 | 36 | client.set_current_dir(current_dir) |
|
37 | 37 | }) |
|
38 | 38 | .and_then(|client| { |
|
39 | 39 | client.attach_io(io::stdin(), io::stdout(), io::stderr()) |
|
40 | 40 | }) |
|
41 | 41 | .and_then(|client| { |
|
42 | 42 | let pid = client.server_spec().process_id.unwrap(); |
|
43 | 43 | let pgid = client.server_spec().process_group_id; |
|
44 | 44 | procutil::setup_signal_handler_once(pid, pgid)?; |
|
45 | 45 | Ok(client) |
|
46 | 46 | }) |
|
47 | 47 | .and_then(|client| { |
|
48 | 48 | client.run_command_chg(handler, env::args_os().skip(1)) |
|
49 | 49 | }) |
|
50 | 50 | .map(|(_client, _handler, code)| { |
|
51 | 51 | procutil::restore_signal_handler_once()?; |
|
52 | 52 | Ok(code) |
|
53 | 53 | }) |
|
54 | 54 | .or_else(|err| Ok(Err(err))) // pass back error to caller |
|
55 | 55 | .map(|res| result_tx.send(res).unwrap()); |
|
56 | 56 | tokio::run(fut); |
|
57 | 57 | result_rx.wait().unwrap_or(Err(io::Error::new(io::ErrorKind::Other, |
|
58 | 58 | "no exit code set"))) |
|
59 | 59 | } |
General Comments 0
You need to be logged in to leave comments.
Login now