mirror of
https://github.com/anthonyoteri/dredge.git
synced 2026-06-05 15:26:53 -04:00
Code cleanup
Fix some minor issues detected by automated code inspection tools.
This commit is contained in:
+1
-11
@@ -72,23 +72,13 @@ impl From<LogLevel> for log::LevelFilter {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
pub struct TagsArgs {
|
||||
/// The image name.
|
||||
#[arg(
|
||||
long,
|
||||
num_args = 0..=1
|
||||
)]
|
||||
pub(crate) name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
pub enum Commands {
|
||||
/// Fetch the list of available repositories from the catalog.
|
||||
Catalog,
|
||||
|
||||
/// Fetch the list of tags for a given image.
|
||||
Tags(TagsArgs),
|
||||
Tags { name: String },
|
||||
|
||||
/// Perform a simple API Version check towards the configured registry
|
||||
/// endpoint.
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
//! Command module responsible for handling the "catalog" command.
|
||||
//!
|
||||
//! The "catalog" command works with the Docker Registry API's "catalog"
|
||||
//! entitity available at /v2/_catalog.
|
||||
//! The "catalog" command works with the Docker Registry APIs "catalog"
|
||||
//! entity available at /v2/_catalog.
|
||||
//!
|
||||
use serde::Deserialize;
|
||||
|
||||
@@ -25,7 +25,7 @@ use crate::api;
|
||||
use crate::config::Config;
|
||||
use crate::error::ApiError;
|
||||
|
||||
/// Path to the Docker Registry API's "catalog" entity.
|
||||
/// Path to the Docker Registry APIs "catalog" entity.
|
||||
const BASE_CATALOG_URI: &str = "/v2/_catalog";
|
||||
|
||||
/// Handler for the `Catalog` endpoint
|
||||
|
||||
@@ -16,17 +16,16 @@
|
||||
|
||||
//! Command module responsible for handling the "tags" command.
|
||||
//!
|
||||
//! The "tags" command works with the Docker Registry API's "tags"
|
||||
//! entitity available at /v2/<name>/tags/list.
|
||||
//! The "tags" command works with the Docker Registry APIs "tags"
|
||||
//! entity available at /v2/<name>/tags/list.
|
||||
//!
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::api;
|
||||
use crate::cli::TagsArgs;
|
||||
use crate::config::Config;
|
||||
use crate::error::ApiError;
|
||||
|
||||
/// Path to the Docker Registry API's "catalog" entity.
|
||||
/// Path to the Docker Registry APIs "catalog" entity.
|
||||
const BASE_TAGS_URI: &str = "/v2/{name}/tags/list";
|
||||
|
||||
/// Handler for the `Tags` endpoint
|
||||
@@ -38,17 +37,15 @@ const BASE_TAGS_URI: &str = "/v2/{name}/tags/list";
|
||||
///
|
||||
/// Returns an `ApiError` if there is a problem fetching or parsing the
|
||||
/// responses from the Docker Registry API.
|
||||
pub async fn handler(config: &Config, args: &TagsArgs) -> Result<(), ApiError> {
|
||||
pub async fn handler(config: &Config, name: &str) -> Result<(), ApiError> {
|
||||
#[derive(Deserialize)]
|
||||
struct Response {
|
||||
name: String,
|
||||
tags: Vec<String>,
|
||||
}
|
||||
|
||||
log::trace!("handler()");
|
||||
|
||||
let name = args.name.clone();
|
||||
let url = BASE_TAGS_URI.replace("{name}", &name);
|
||||
let url = BASE_TAGS_URI.replace("{name}", name);
|
||||
let responses: Vec<Response> = api::fetch_all(config, &url).await?;
|
||||
let tag_list: Vec<&str> = responses
|
||||
.iter()
|
||||
@@ -56,7 +53,7 @@ pub async fn handler(config: &Config, args: &TagsArgs) -> Result<(), ApiError> {
|
||||
.collect();
|
||||
|
||||
for tag in tag_list {
|
||||
println!("{tag}");
|
||||
println!("{name}:{tag}");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
//! Command module responsible for handling the API Version check.
|
||||
//!
|
||||
//! This is a minimal endpoint suitable for ensuring that the configured
|
||||
//! Docker Regsitry API supports the correct API version.
|
||||
//! Docker Registry API supports the correct API version.
|
||||
//!
|
||||
use crate::config::Config;
|
||||
use crate::error::ApiError;
|
||||
|
||||
/// Path to the Docker Registry API's "api version check" endpoint.
|
||||
/// Path to the Docker Registry APIs "api version check" endpoint.
|
||||
const BASE_URL: &str = "/v2";
|
||||
|
||||
/// Handler for the API Version Check.
|
||||
|
||||
+3
-3
@@ -40,7 +40,7 @@ const CONFIG_PREFIX: &str = "dredge";
|
||||
/// Locate the absolute path to the saved configuration file on disk.
|
||||
///
|
||||
/// If given an optional `path` to a configuration file, and that file
|
||||
/// exists on disk, the absoulte path to that file will be returned.
|
||||
/// exists on disk, the absolute path to that file will be returned.
|
||||
/// Otherwise, the XDG configuration path will be used. If neither the
|
||||
/// optional `path` parameter refers to an existing file on disk, nor a
|
||||
/// suitable configuration file can be located within the XDG configuration
|
||||
@@ -75,7 +75,7 @@ fn locate_config_file(path: Option<OsString>) -> Option<PathBuf> {
|
||||
///
|
||||
/// # Errors:
|
||||
///
|
||||
/// This returns a `ConfigError` if a problem occured which prevented either
|
||||
/// This returns a `ConfigError` if a problem occurred which prevented either
|
||||
/// the creation of the directory tree, or in writing the default configuration
|
||||
/// to the file.
|
||||
fn create_default_config_file() -> Result<PathBuf, ConfigError> {
|
||||
@@ -104,7 +104,7 @@ async fn main() -> Result<(), DredgeError> {
|
||||
let config = Config::try_from(config_file.as_ref())?;
|
||||
match args.command {
|
||||
Commands::Catalog => commands::catalog::handler(&config).await?,
|
||||
Commands::Tags(args) => commands::tags::handler(&config, &args).await?,
|
||||
Commands::Tags { name } => commands::tags::handler(&config, &name).await?,
|
||||
Commands::Check => commands::version::handler(&config).await?,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user