use crate::error::Result as CliResult;
use serde_json::Value;
pub use crate::commands::cloud::utils::{
DetailRow, confirm_action, extract_field, format_memory_size, format_status, output_with_pager,
truncate_string,
};
pub use crate::output::{apply_jmespath, handle_output, print_formatted_output, resolve_auto};
pub fn read_json_data(data: &str) -> CliResult<Value> {
let json_str = if data == "-" {
use std::io::Read;
let mut buffer = String::new();
std::io::stdin()
.read_to_string(&mut buffer)
.map_err(|e| anyhow::anyhow!("Failed to read from stdin: {}", e))?;
buffer
} else if let Some(file_path) = data.strip_prefix('@') {
std::fs::read_to_string(file_path)
.map_err(|e| anyhow::anyhow!("Failed to read file {}: {}", file_path, e))?
} else {
data.to_string()
};
serde_json::from_str(&json_str).map_err(|e| anyhow::anyhow!("Invalid JSON: {}", e).into())
}
pub fn format_bytes(bytes: u64) -> String {
format_memory_size(bytes as f64 / (1024.0 * 1024.0 * 1024.0))
}