Skip to content

Commit d87a821

Browse files
committed
Add an option to show image digests.
The 'tags' command now includes the option -d/--digest. If set, the image tags table will include a column with the image digest.
1 parent 74b873d commit d87a821

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/hubapi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ pub struct Image {
4545
pub architecture: String,
4646
pub os: String,
4747
pub size: u64,
48+
pub digest: Option<String>,
4849
}

src/options.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ pub struct TagsOptions {
4545
#[options(help = "Limit the number of results", default = "30")]
4646
pub limit: usize,
4747

48+
#[options(help = "Show image digest")]
49+
pub digest: bool,
50+
4851
#[options(help = "Filter by architecture")]
4952
pub architecture: Option<String>,
5053

src/tags.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,19 @@ struct Response {
3232

3333
pub async fn run(options: TagsOptions) -> anyhow::Result<()> {
3434
macro_rules! row {
35-
($($values:tt)*) => {
36-
println!("{:10} {:8.8} {:6.6} {:15} {}", $($values)*)
37-
}
35+
($size:expr, $os:expr, $arch:expr, $push:expr, $digest:expr, $name:expr) => {
36+
if options.digest {
37+
println!(
38+
"{:10} {:8.8} {:6.6} {:14} {:73} {}",
39+
$size, $os, $arch, $push, $digest, $name
40+
)
41+
} else {
42+
println!(
43+
"{:10} {:8.8} {:6.6} {:15} {}",
44+
$size, $os, $arch, $push, $name
45+
)
46+
}
47+
};
3848
}
3949

4050
let filter_os;
@@ -79,7 +89,7 @@ pub async fn run(options: TagsOptions) -> anyhow::Result<()> {
7989
if page == 1 {
8090
println!("- {} results for {}", response.count, repository);
8191

82-
row!("SIZE", "OS", "ARCH", "LAST PUSHED", "NAME");
92+
row!("SIZE", "OS", "ARCH", "LAST PUSHED", "DIGEST", "NAME");
8393
}
8494

8595
if response.results.is_empty() {
@@ -112,6 +122,7 @@ pub async fn run(options: TagsOptions) -> anyhow::Result<()> {
112122
image.os,
113123
image.architecture,
114124
last_updated,
125+
image.digest.as_deref().unwrap_or_default(),
115126
result.name
116127
);
117128
}

0 commit comments

Comments
 (0)