cargo-drone 0.4.3

A cargo subcommand for Drone.
Documentation
//! `Drone.toml` config.

use failure::Error;
use std::env;
use std::fs::File;
use std::io::prelude::*;
use toml;

/// Root config.
#[derive(Deserialize)]
pub struct Root {
  /// LLVM target.
  pub target: String,
  /// LLVM test target.
  pub test_target: String,
  /// Test cross-compile toolchain.
  pub test_cross_compile: Option<String>,
  /// OpenOCD config.
  pub openocd: Option<Openocd>,
  /// ITM config.
  pub itm: Option<Itm>,
}

/// OpenOCD config.
#[derive(Deserialize)]
pub struct Openocd {
  /// Config files.
  pub config: Vec<String>,
}

/// ITM config.
#[derive(Deserialize)]
pub struct Itm {
  /// ITM frequency.
  pub frequency: u32,
}

/// Reads and parses `Drone.toml` config.
pub fn read() -> Result<Root, Error> {
  let path = env::current_dir()?.join("Drone.toml");
  let mut buffer = String::new();
  let mut file = File::open(&path)?;
  file.read_to_string(&mut buffer)?;
  Ok(toml::from_str(&buffer)?)
}