use thiserror::Error;
use url::Url;
#[derive(Error, Debug)]
pub enum ParameterError {
#[error("API path has no segments {0}")]
APIPathNeedsSegments(Url),
#[error("API path segments has no last")]
APIPathSegmentsNeedsLast,
#[error("Must provide API spec url if no local file given")]
APIUrlNeededIfNoLocalFile,
#[error("Must provide a path to create the testing yaml spec")]
TestingYAMLSpecPathMissing,
}
pub fn try_file_name_from_path_url(path_url: &Url) -> Result<String, ParameterError> {
path_url
.path_segments()
.ok_or_else(|| ParameterError::APIPathNeedsSegments(path_url.clone()))
.and_then(|path_segments| {
path_segments
.last()
.ok_or_else(|| ParameterError::APIPathSegmentsNeedsLast)
.map(ToString::to_string)
})
}