Skip to content

Commit 055f4e9

Browse files
authored
client: Consistently accept --debug (#96)
To debug things. Signed-off-by: Colin Walters <[email protected]>
1 parent e4196da commit 055f4e9

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

examples/client.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,30 @@ use oci_spec::image::{Digest, ImageManifest};
77
use tokio::io::AsyncReadExt;
88

99
#[derive(clap::Parser, Debug)]
10-
struct GetMetadataOpts {
11-
/// The skopeo-style transport:image reference
12-
reference: String,
10+
struct CommonOpts {
11+
/// Emit debugging to stderr
12+
#[clap(long)]
13+
debug: bool,
1314

1415
/// Disable TLS verification
1516
#[clap(long)]
1617
insecure: bool,
1718
}
1819

20+
#[derive(clap::Parser, Debug)]
21+
struct GetMetadataOpts {
22+
#[clap(flatten)]
23+
common: CommonOpts,
24+
25+
/// The skopeo-style transport:image reference
26+
reference: String,
27+
}
28+
1929
#[derive(clap::Parser, Debug)]
2030
struct GetBlobOpts {
31+
#[clap(flatten)]
32+
common: CommonOpts,
33+
2134
/// The skopeo-style transport:image reference
2235
reference: String,
2336

@@ -54,9 +67,12 @@ struct Metadata {
5467
manifest: ImageManifest,
5568
}
5669

57-
impl GetMetadataOpts {
58-
fn proxy_opts(&self) -> containers_image_proxy::ImageProxyConfig {
70+
impl CommonOpts {
71+
fn to_config(self) -> ImageProxyConfig {
5972
let mut r = ImageProxyConfig::default();
73+
if self.debug {
74+
r.debug = true;
75+
}
6076
if self.insecure {
6177
r.insecure_skip_tls_verification = Some(true)
6278
}
@@ -65,7 +81,7 @@ impl GetMetadataOpts {
6581
}
6682

6783
async fn get_metadata(o: GetMetadataOpts) -> Result<()> {
68-
let config = o.proxy_opts();
84+
let config = o.common.to_config();
6985
let proxy = containers_image_proxy::ImageProxy::new_with_config(config).await?;
7086
let img = proxy.open_image(&o.reference).await?;
7187
let (digest, manifest) = proxy.fetch_manifest(&img).await?;
@@ -75,7 +91,8 @@ async fn get_metadata(o: GetMetadataOpts) -> Result<()> {
7591
}
7692

7793
async fn get_blob(o: GetBlobOpts) -> Result<()> {
78-
let proxy = containers_image_proxy::ImageProxy::new().await?;
94+
let config = o.common.to_config();
95+
let proxy = containers_image_proxy::ImageProxy::new_with_config(config).await?;
7996
let img = proxy.open_image(&o.reference).await?;
8097
let (mut blob, driver) = proxy.get_blob(&img, &o.digest, o.size).await?;
8198

@@ -98,7 +115,8 @@ async fn get_blob(o: GetBlobOpts) -> Result<()> {
98115
}
99116

100117
async fn get_blob_raw(o: GetBlobOpts) -> Result<()> {
101-
let proxy = containers_image_proxy::ImageProxy::new().await?;
118+
let config = o.common.to_config();
119+
let proxy = containers_image_proxy::ImageProxy::new_with_config(config).await?;
102120
let img = proxy.open_image(&o.reference).await?;
103121
let (_, mut datafd, err) = proxy.get_raw_blob(&img, &o.digest).await?;
104122

@@ -121,7 +139,7 @@ async fn get_blob_raw(o: GetBlobOpts) -> Result<()> {
121139
}
122140

123141
async fn fetch_container_to_devnull(o: FetchContainerToDevNullOpts) -> Result<()> {
124-
let config = o.metaopts.proxy_opts();
142+
let config = o.metaopts.common.to_config();
125143
let proxy = containers_image_proxy::ImageProxy::new_with_config(config).await?;
126144
let img = &proxy.open_image(&o.metaopts.reference).await?;
127145
let manifest = proxy.fetch_manifest(img).await?.1;

0 commit comments

Comments
 (0)