release_manager/
lib.rs

1// This file is part of Release Manager
2
3// Release Manager is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7
8// Release Manager is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11// GNU General Public License for more details.
12
13// You should have received a copy of the GNU General Public License
14// along with Release Manager  If not, see <http://www.gnu.org/licenses/>.
15
16#![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}