Rename "repo list" command to "catalog"

The official Docker Registry V2 API calls the commmand to list the repositories
the "catalog", so to keep things as consistent as possible and not invent new
names for things that have meaning in the domain, stick with the same naming
convention.
This commit is contained in:
Anthony Oteri
2023-09-14 09:24:09 -04:00
parent 0a112ed56f
commit 00a1ad87e7
4 changed files with 13 additions and 43 deletions
+1 -12
View File
@@ -54,16 +54,5 @@ impl From<LogLevel> for log::LevelFilter {
#[derive(Debug, Subcommand)] #[derive(Debug, Subcommand)]
pub enum Commands { pub enum Commands {
Repo(RepoArgs), Catalog,
}
#[derive(Debug, Args)]
pub struct RepoArgs {
#[command(subcommand)]
pub command: RepoCommands,
}
#[derive(Debug, Subcommand)]
pub enum RepoCommands {
List,
} }
+1 -1
View File
@@ -1 +1 @@
pub mod repo; pub mod catalog;
@@ -1,35 +1,16 @@
//! Command module responsible for handling the "repo" command. //! Command module responsible for handling the "catalog" command.
//! //!
//! The "repo" command works with the Docker Registry API's "repository" //! The "catalog" command works with the Docker Registry API's "catalog"
//! entitity available at /v2/_catalog. //! entitity available at /v2/_catalog.
//! //!
use crate::cli::{RepoArgs, RepoCommands};
use crate::config::Config; use crate::config::Config;
use crate::error::ApiError; use crate::error::ApiError;
use serde::Deserialize; use serde::Deserialize;
/// Path to the Docker Registry API's "repository" entity. /// Path to the Docker Registry API's "catalog" entity.
const BASE_CATALOG_URI: &str = "/v2/_catalog?n=1000"; const BASE_CATALOG_URI: &str = "/v2/_catalog";
/// Main handler function for the "repo" command. /// Handler for the `Catalog` endpoint
///
/// Responsible for dispatching the various subcommands.
///
/// # Errors:
///
/// Returns an `ApiError` if there is a problem handling the requested
/// subcommand.
pub async fn handler(config: &Config, args: &RepoArgs) -> Result<(), ApiError> {
log::trace!("handler()");
match args.command {
RepoCommands::List => handle_list(config, args).await?,
}
Ok(())
}
/// Handle the repository list command.
/// ///
/// Fetch the list of repository names from the Docker Registry API, and /// Fetch the list of repository names from the Docker Registry API, and
/// simply print the resulting names to stdout. /// simply print the resulting names to stdout.
@@ -38,22 +19,22 @@ pub async fn handler(config: &Config, args: &RepoArgs) -> Result<(), ApiError> {
/// ///
/// Returns an `ApiError` if there is a problem fetching or parsing the /// Returns an `ApiError` if there is a problem fetching or parsing the
/// responses from the Docker Registry API. /// responses from the Docker Registry API.
async fn handle_list(config: &Config, _args: &RepoArgs) -> Result<(), ApiError> { pub async fn handler(config: &Config) -> Result<(), ApiError> {
#[derive(Deserialize)] #[derive(Deserialize)]
struct Response { struct Response {
repositories: Vec<String>, repositories: Vec<String>,
} }
log::trace!("handle_list()"); log::trace!("handler()");
let responses: Vec<Response> = fetch_all(config, BASE_CATALOG_URI).await?; let responses: Vec<Response> = fetch_all(config, BASE_CATALOG_URI).await?;
let repo_list: Vec<&str> = responses let repository_list: Vec<&str> = responses
.iter() .iter()
.flat_map(|r| r.repositories.iter().map(String::as_str)) .flat_map(|r| r.repositories.iter().map(String::as_str))
.collect(); .collect();
for repo in repo_list { for repository in repository_list {
println!("{repo}"); println!("{repository}");
} }
Ok(()) Ok(())
+1 -1
View File
@@ -86,7 +86,7 @@ async fn main() -> Result<(), DredgeError> {
let config = Config::try_from(config_file.as_ref())?; let config = Config::try_from(config_file.as_ref())?;
match args.command { match args.command {
Commands::Repo(repo_args) => commands::repo::handler(&config, &repo_args).await?, Commands::Catalog => commands::catalog::handler(&config).await?,
} }
Ok(()) Ok(())