solvastro 0.1.1

A Rust blind plate solver
Documentation
use std::env;
use std::error::Error;
use std::ffi::OsString;
use std::fs::File;
use std::io::BufReader;

use crate::structs_f64::query::Query;
use std::path::Path;

/// Returns the first positional argument sent to this process. If there are no
/// positional arguments, then this returns an error.
#[cfg(not(tarpaulin_include))]
pub fn get_first_arg() -> Result<OsString, Box<dyn Error>> {
    get_arg(1)
}

#[cfg(not(tarpaulin_include))]
pub fn get_second_arg() -> Result<OsString, Box<dyn Error>> {
    get_arg(2)
}

#[cfg(not(tarpaulin_include))]
pub fn get_arg(index: usize) -> Result<OsString, Box<dyn Error>> {
    //println!("{:?}", env::args_os().nth(index));

    match env::args_os().nth(index) {
        None => Err(From::from("expected 1 argument, but got none")),
        Some(file_path) => Ok(file_path),
    }
}

pub fn parse_input_file(filename: &Path) -> Result<Query, Box<dyn Error>> {
    let file = File::open(filename)?;
    let reader = BufReader::new(file);

    let result: Query = serde_json::from_reader(reader)?;

    Ok(result)
}