hen 0.8.1

Run API collections from the command line.
use log::debug;

use crate::{parser, request::Request};
use std::path::PathBuf;

#[derive(Debug)]
pub struct Collection {
    pub name: String,
    pub description: String,
    pub requests: Vec<Request>,
}

// import the collection file, parse it, and return a Collection struct.
impl Collection {
    pub fn new(collection_path: PathBuf) -> Result<Self, pest::error::Error<parser::Rule>> {
        let working_dir = collection_path.parent().unwrap().to_path_buf();
        // if the working dir is the root, set it to the current working directory
        let working_dir = if working_dir.to_str().unwrap() == "" {
            std::env::current_dir().unwrap()
        } else {
            working_dir
        };

        debug!("Working dir: {:?}", working_dir);

        let input = std::fs::read_to_string(collection_path).map_err(|e| {
            pest::error::Error::new_from_span(
                pest::error::ErrorVariant::CustomError {
                    message: e.to_string(),
                },
                pest::Span::new("", 0, 0).unwrap(),
            )
        })?;
        parser::parse_collection(input.as_str(), working_dir)
    }
}