]> git.lizzy.rs Git - rust.git/blob - src/librustc_driver/args.rs
Fix rebase fallout.
[rust.git] / src / librustc_driver / args.rs
1 use std::error;
2 use std::fmt;
3 use std::fs;
4 use std::io;
5 use std::str;
6
7 pub fn arg_expand(arg: String) -> Result<Vec<String>, Error> {
8     if arg.starts_with("@") {
9         let path = &arg[1..];
10         let file = match fs::read_to_string(path) {
11             Ok(file) => file,
12             Err(ref err) if err.kind() == io::ErrorKind::InvalidData => {
13                 return Err(Error::Utf8Error(Some(path.to_string())));
14             }
15             Err(err) => return Err(Error::IOError(path.to_string(), err)),
16         };
17         Ok(file.lines().map(ToString::to_string).collect())
18     } else {
19         Ok(vec![arg])
20     }
21 }
22
23 #[derive(Debug)]
24 pub enum Error {
25     Utf8Error(Option<String>),
26     IOError(String, io::Error),
27 }
28
29 impl fmt::Display for Error {
30     fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
31         match self {
32             Error::Utf8Error(None) => write!(fmt, "Utf8 error"),
33             Error::Utf8Error(Some(path)) => write!(fmt, "Utf8 error in {}", path),
34             Error::IOError(path, err) => write!(fmt, "IO Error: {}: {}", path, err),
35         }
36     }
37 }
38
39 impl error::Error for Error {
40     fn description(&self) -> &'static str {
41         "argument error"
42     }
43 }