#![allow(dead_code)]
use crate::errors::CliError;
use std::path::Path;
pub fn validate_container_id(container_id: &str) -> Result<(), CliError> {
if container_id.len() < 8 {
return Err(CliError::InvalidInput(
"Container ID must be at least 8 characters".to_string(),
));
}
if container_id.len() > 64 {
return Err(CliError::InvalidInput(
"Container ID appears invalid (too long for NeoFS format)".to_string(),
));
}
Ok(())
}
pub fn validate_file_path(path: &Path) -> Result<(), CliError> {
if !path.exists() {
return Err(CliError::FileSystem(format!("File not found: {path}", path = path.display())));
}
if !path.is_file() {
return Err(CliError::FileSystem(format!(
"Path is not a file: {path}",
path = path.display()
)));
}
Ok(())
}
pub fn validate_directory_path(path: &Path) -> Result<(), CliError> {
if !path.exists() {
return Err(CliError::FileSystem(format!(
"Directory not found: {path}",
path = path.display()
)));
}
if !path.is_dir() {
return Err(CliError::FileSystem(format!(
"Path is not a directory: {path}",
path = path.display()
)));
}
Ok(())
}
pub fn format_size(size: u64) -> String {
const KB: u64 = 1024;
const MB: u64 = KB * 1024;
const GB: u64 = MB * 1024;
if size < KB {
format!("{size} B")
} else if size < MB {
format!("{:.2} KB", size as f64 / KB as f64)
} else if size < GB {
format!("{:.2} MB", size as f64 / MB as f64)
} else {
format!("{:.2} GB", size as f64 / GB as f64)
}
}
pub fn validate_endpoint(endpoint: &str) -> Result<(), CliError> {
if !endpoint.starts_with("http://") && !endpoint.starts_with("https://") {
return Err(CliError::InvalidInput(
"Endpoint must start with http:// or https://".to_string(),
));
}
if endpoint.len() < 12 || !endpoint.contains('.') {
return Err(CliError::InvalidInput("Endpoint format appears invalid".to_string()));
}
Ok(())
}
pub fn get_node_info(_endpoint: &str) -> Result<String, CliError> {
Err(CliError::Network(
"NeoFS node info retrieval requires comprehensive network integration. Use external NeoFS tools to query node status.".to_string(),
))
}
pub fn check_endpoint_availability(endpoint: &str) -> Result<bool, CliError> {
validate_endpoint(endpoint)?;
Err(CliError::Network(
"NeoFS endpoint availability checking requires comprehensive connectivity integration. Use external NeoFS tools to test connectivity.".to_string(),
))
}
pub fn format_permissions(is_public_read: bool, is_public_write: bool) -> String {
match (is_public_read, is_public_write) {
(true, true) => "Public read/write".to_string(),
(true, false) => "Public read only".to_string(),
(false, true) => "Public write only".to_string(),
(false, false) => "Private".to_string(),
}
}