use std::path::{ Path, PathBuf };
use crate::artifact::ArtifactKind;
#[ derive( Debug ) ]
pub enum AssetPathsError
{
EnvVarNotSet,
}
impl core::fmt::Display for AssetPathsError
{
#[ inline ]
fn fmt( &self, f : &mut core::fmt::Formatter< '_ > ) -> core::fmt::Result
{
match self
{
Self::EnvVarNotSet => write!(
f,
"environment variable $PRO_CLAUDE is not set \
(fallback: set $PRO and ensure $PRO/genai/claude/ exists) \
— run: export PRO_CLAUDE=/path/to/your/claude-assets"
),
}
}
}
impl core::error::Error for AssetPathsError {}
#[ derive( Debug, Clone ) ]
pub struct AssetPaths
{
source_root : PathBuf,
target_root : PathBuf,
}
impl AssetPaths
{
#[ inline ]
pub fn from_env() -> Result< Self, AssetPathsError >
{
let source_root = if let Ok( v ) = std::env::var( "PRO_CLAUDE" )
{
PathBuf::from( v )
}
else if let Ok( pro ) = std::env::var( "PRO" )
{
PathBuf::from( pro ).join( "genai" ).join( "claude" )
}
else
{
return Err( AssetPathsError::EnvVarNotSet );
};
let target_root = std::env::current_dir().unwrap_or_else( |_| PathBuf::from( "." ) );
Ok( Self { source_root, target_root } )
}
#[ must_use ]
#[ inline ]
pub fn new( source_root : PathBuf, target_root : PathBuf ) -> Self
{
Self { source_root, target_root }
}
#[ must_use ]
#[ inline ]
pub fn source_dir( &self, kind : ArtifactKind ) -> PathBuf
{
self.source_root.join( kind.source_subdir() )
}
#[ must_use ]
#[ inline ]
pub fn target_dir( &self, kind : ArtifactKind ) -> PathBuf
{
self.target_root.join( ".claude" ).join( kind.target_subdir() )
}
#[ must_use ]
#[ inline ]
pub fn source_root( &self ) -> &Path
{
&self.source_root
}
}