use anyhow::Result;
use crate::config::Config;
use crate::make_tokio_runtime;
use crate::params::config::ConfigParams;
#[derive(Debug, clap::Parser)]
#[command(
name = "stat",
about = "Show object metadata",
disable_version_flag = true
)]
pub struct StatCmd {
#[command(flatten)]
pub config_params: ConfigParams,
#[arg()]
pub target: String,
}
impl StatCmd {
pub fn run(self) -> Result<()> {
make_tokio_runtime(1).block_on(self.do_run())
}
async fn do_run(self) -> Result<()> {
let cfg = Config::load(&self.config_params.config)?;
let target = &self.target;
println!("path: {target}");
let (op, path) = cfg.parse_location(target)?;
let meta = op.stat(&path).await?;
let size = meta.content_length();
println!("size: {size}");
if let Some(etag) = meta.etag() {
println!("etag: {etag}");
}
let file_type = meta.mode();
println!("type: {file_type}");
if let Some(content_type) = meta.content_type() {
println!("content-type: {content_type}");
}
if let Some(last_modified) = meta.last_modified() {
println!("last-modified: {last_modified}");
}
Ok(())
}
}