1#![feature(entry_and_modify)]
17#![feature(try_from)]
18
19extern crate toml;
20extern crate serde;
21extern crate structopt;
22extern crate zip;
23
24#[macro_use]
25extern crate serde_derive;
26
27#[macro_use]
28extern crate structopt_derive;
29
30#[macro_use]
31extern crate log;
32
33mod error;
34mod target;
35mod config;
36mod status;
37mod commandline;
38
39use std::process::{Command, ExitStatus};
40use std::fs::File;
41use std::io::prelude::*;
42use std::path::Path;
43use toml::Value;
44
45pub use target::{Arch, OS, Target};
46pub use error::Error;
47pub use config::{Config, ConfigState, ConfigTrait, TargetConfig};
48pub use status::{StatusWrapper, Status, VersionStatus, BuildStatus};
49pub use commandline::Opt;
50
51pub fn parse_toml<T>(filename: &Path) -> Result<T, Error>
52where
53 T: serde::de::DeserializeOwned,
54{
55 let mut f = File::open(filename)?;
56 let mut contents = String::new();
57 f.read_to_string(&mut contents)?;
58 Ok(toml::from_str(&contents)?)
59}
60
61pub fn table_str<'a>(table: &'a Value, name: &str, missing_err: Error) -> Result<&'a str, Error> {
62 table.get(name).ok_or(missing_err).and_then(
63 |value| match value {
64 &Value::String(ref v) => Ok(v.as_ref()),
65 _ => Err(Error::NotString),
66 },
67 )
68}
69
70pub fn publish() -> Result<ExitStatus, Error> {
71 Command::new("cargo").arg("publish").status().map_err(
72 |e| e.into(),
73 )
74}