This repository was archived by the owner on Jun 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathracerd.rs
81 lines (67 loc) · 2.21 KB
/
racerd.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
extern crate docopt;
extern crate env_logger;
extern crate libracerd;
#[macro_use]
extern crate serde_derive;
use libracerd::engine::SemanticEngine;
use libracerd::{engine, http, Config};
use std::convert::Into;
use docopt::Docopt;
const VERSION: &str = env!("CARGO_PKG_VERSION");
const USAGE: &str = "
racerd - a JSON/HTTP layer on top of racer
Usage:
racerd serve [--secret-file=<path>] [--port=<int>] [--addr=<address>] [-l] [--rust-src-path=<path>]
racerd (-h | --help)
racerd --version
Options:
-c, --rust-src-path=<path> Use the given path for std library completions
-l, --logging Print http logs.
-h, --help Show this message.
-p, --port=<int> Listen on this port [default: 3048].
-a, --addr=<address> Listen on this address [default: 127.0.0.1].
-s, --secret-file=<path> Path to the HMAC secret file. File will be destroyed after being read.
--version Print the version and exit.
";
#[derive(Debug, Deserialize)]
struct Args {
flag_port: u16,
flag_addr: String,
flag_version: bool,
flag_secret_file: Option<String>,
flag_logging: bool,
flag_rust_src_path: Option<String>,
cmd_serve: bool,
}
impl Into<Config> for Args {
fn into(self) -> Config {
Config {
port: self.flag_port as u16,
secret_file: self.flag_secret_file,
print_http_logs: self.flag_logging,
rust_src_path: self.flag_rust_src_path,
addr: self.flag_addr,
}
}
}
fn main() {
// Start logging
env_logger::init();
// Parse arguments
let args: Args = Docopt::new(USAGE)
.and_then(|d| d.deserialize())
.unwrap_or_else(|e| e.exit());
// Print version and exit if --version was specified
if args.flag_version {
println!("racerd version {}", VERSION);
std::process::exit(0);
}
// build config object
let config: Config = args.into();
// TODO start specified semantic engine. For now, hard coded racer.
let racer = engine::Racer::new();
racer.initialize(&config).unwrap();
// Start serving
let server = http::serve(&config, racer).unwrap();
println!("racerd listening at {}", server.addr());
}