Skip to content

Commit c3b9bdc

Browse files
committed
Restructure to enable multiple providers. Add basic command options.
Signed-off-by: Michael Nelson <[email protected]>
1 parent 01606ca commit c3b9bdc

File tree

7 files changed

+315
-57
lines changed

7 files changed

+315
-57
lines changed

cmd/oci-catalog/Cargo.lock

+172
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/oci-catalog/Cargo.toml

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ version = "0.1.0"
77
edition = "2021"
88

99
[dependencies]
10-
tonic = "0.9"
10+
clap = { version = "4.3", features = ["derive", "env"] }
11+
env_logger = "0.10"
12+
futures-core = "0.3"
13+
log = "0.4"
1114
prost = "0.11"
1215
tokio = { version = "1.0", features = ["macros", "rt-multi-thread"] }
1316
tokio-stream = "0.1"
14-
futures-core = "0.3"
17+
tonic = "0.9"
1518
reqwest = "0.11"
1619

1720
[build-dependencies]

cmd/oci-catalog/build.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
// Copyright 2023 the Kubeapps contributors.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
use std::env;
5+
46
fn main() -> Result<(), Box<dyn std::error::Error>> {
57
tonic_build::compile_protos("proto/ocicatalog.proto")?;
8+
9+
// If the binary is built with the ENV var "OCI_CATALOG_VERSION",
10+
// the value will be available at buildime. Otherwise, it becomes "devel"
11+
// We use this ENV var to display a custom version when passing the "-- version"
12+
// flag
13+
let version = env::var("OCI_CATALOG_VERSION").unwrap_or("devel".to_string());
14+
println!("cargo:rustc-env=OCI_CATALOG_VERSION={}", version);
15+
616
Ok(())
717
}

cmd/oci-catalog/src/cli.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2023 the Kubeapps contributors.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use clap;
5+
6+
#[derive(clap::Parser, Debug)]
7+
#[command(version = env!("OCI_CATALOG_VERSION"))]
8+
/// A service that returns catalog information for an OCI repository.
9+
///
10+
/// The OCI Catalog service uses a strategy pattern to enable listing catalog
11+
/// information for different OCI provider registries, until a standard is set
12+
/// for requesting namespaced repositories of a registry in the OCI Distribution
13+
/// specification.
14+
pub struct Options {
15+
#[arg(
16+
short = 'p',
17+
long = "port",
18+
env = "OCI_CATALOG_PORT",
19+
default_value = "50001",
20+
help = "Specify the port on which oci-catalog gRPC service listens."
21+
)]
22+
pub port: u16,
23+
}
24+
25+
#[cfg(test)]
26+
mod tests {
27+
use super::*;
28+
29+
#[test]
30+
fn test_cli() {
31+
use clap::CommandFactory;
32+
Options::command().debug_assert();
33+
}
34+
}

0 commit comments

Comments
 (0)