generated from EmbarkStudios/opensource-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstat.rs
67 lines (59 loc) · 1.96 KB
/
stat.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use crate::{color::ColorCtx, util};
use anyhow::Context as _;
#[derive(clap::Parser, Debug)]
pub struct Args {
/// The gs:// url to the object to stat
url: url::Url,
}
pub async fn cmd(ctx: &util::RequestContext, args: Args) -> anyhow::Result<()> {
let oid = util::gs_url_to_object_id(&args.url)?;
let cc = ColorCtx::from_env();
let get_req = ctx.obj.get(
&(
oid.bucket(),
oid.object().context("invalid object name specified")?,
),
None,
)?;
let get_res: tame_gcs::objects::GetObjectResponse = util::execute(ctx, get_req).await?;
let md = get_res.metadata;
// Print out the information the same way gsutil does, except with RFC-2822 date formatting
println!("{}", cc.paint(nu_ansi_term::Color::Cyan, args.url.as_str()));
println!(
" Creation time:\t{}",
md.time_created
.expect("time_created")
.format(&time::format_description::well_known::Rfc2822)
.unwrap()
);
println!(
" Update time:\t{}",
md.updated
.expect("updated")
.format(&time::format_description::well_known::Rfc2822)
.unwrap()
);
println!(
" Storage class:\t{}",
md.storage_class.expect("storage_class")
);
println!(" Content-Length:\t{}", md.size.expect("size"));
println!(
" Content-Type:\t{}",
md.content_type.as_deref().unwrap_or("None")
);
if let Some(md) = &md.metadata {
for (k, v) in md {
println!(" {k}:\t\t{v}");
}
}
println!(" Hash (crc32c):\t{}", md.crc32c.expect("crc32c"));
println!(" Hash (md5):\t\t{}", md.md5_hash.expect("md5_hash"));
println!(" ETag:\t\t{}", md.etag.expect("etag"));
println!(" Generation:\t\t{}", md.generation.expect("generation"));
println!(
" Metageneration:\t{}",
md.metageneration.expect("metageneration")
);
Ok(())
}