Skip to main content

validate_file_extension

Function validate_file_extension 

Source
pub fn validate_file_extension(
    path: &Path,
    arg_name: &str,
    allowed: &[String],
) -> Result<()>
Expand description

Validate that a file has an allowed extension.

The comparison is case-insensitive. Extensions should be provided without the leading dot (e.g., "yaml", not ".yaml").

§Arguments

  • path - The path whose extension to check
  • arg_name - The argument name (used in error messages)
  • allowed - List of allowed extensions (without leading dot)

§Returns

  • Ok(()) if the extension is in the allowed list
  • Err(ValidationError::InvalidExtension) otherwise

§Example

use dynamic_cli::validator::validate_file_extension;
use std::path::Path;

let allowed = vec!["yaml".to_string(), "yml".to_string()];
validate_file_extension(Path::new("config.yaml"), "config", &allowed)?;