Code cleanup

Fix some minor issues detected by automated code inspection tools.
This commit is contained in:
Anthony Oteri
2023-09-18 14:37:10 -04:00
parent d450bccf9a
commit 6f44b77a6d
6 changed files with 16 additions and 28 deletions
+1
View File
@@ -1,5 +1,6 @@
version: 2 version: 2
updates: updates:
- package-ecosystem: "cargo" - package-ecosystem: "cargo"
directory: /
schedule: schedule:
interval: "daily" interval: "daily"
+1 -11
View File
@@ -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)] #[derive(Debug, Subcommand)]
pub enum Commands { pub enum Commands {
/// Fetch the list of available repositories from the catalog. /// Fetch the list of available repositories from the catalog.
Catalog, Catalog,
/// Fetch the list of tags for a given image. /// Fetch the list of tags for a given image.
Tags(TagsArgs), Tags { name: String },
/// Perform a simple API Version check towards the configured registry /// Perform a simple API Version check towards the configured registry
/// endpoint. /// endpoint.
+3 -3
View File
@@ -16,8 +16,8 @@
//! Command module responsible for handling the "catalog" command. //! Command module responsible for handling the "catalog" command.
//! //!
//! The "catalog" command works with the Docker Registry API's "catalog" //! The "catalog" command works with the Docker Registry APIs "catalog"
//! entitity available at /v2/_catalog. //! entity available at /v2/_catalog.
//! //!
use serde::Deserialize; use serde::Deserialize;
@@ -25,7 +25,7 @@ use crate::api;
use crate::config::Config; use crate::config::Config;
use crate::error::ApiError; 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"; const BASE_CATALOG_URI: &str = "/v2/_catalog";
/// Handler for the `Catalog` endpoint /// Handler for the `Catalog` endpoint
+6 -9
View File
@@ -16,17 +16,16 @@
//! Command module responsible for handling the "tags" command. //! Command module responsible for handling the "tags" command.
//! //!
//! The "tags" command works with the Docker Registry API's "tags" //! The "tags" command works with the Docker Registry APIs "tags"
//! entitity available at /v2/<name>/tags/list. //! entity available at /v2/<name>/tags/list.
//! //!
use serde::Deserialize; use serde::Deserialize;
use crate::api; use crate::api;
use crate::cli::TagsArgs;
use crate::config::Config; use crate::config::Config;
use crate::error::ApiError; 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"; const BASE_TAGS_URI: &str = "/v2/{name}/tags/list";
/// Handler for the `Tags` endpoint /// 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 /// Returns an `ApiError` if there is a problem fetching or parsing the
/// responses from the Docker Registry API. /// 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)] #[derive(Deserialize)]
struct Response { struct Response {
name: String,
tags: Vec<String>, tags: Vec<String>,
} }
log::trace!("handler()"); 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 responses: Vec<Response> = api::fetch_all(config, &url).await?;
let tag_list: Vec<&str> = responses let tag_list: Vec<&str> = responses
.iter() .iter()
@@ -56,7 +53,7 @@ pub async fn handler(config: &Config, args: &TagsArgs) -> Result<(), ApiError> {
.collect(); .collect();
for tag in tag_list { for tag in tag_list {
println!("{tag}"); println!("{name}:{tag}");
} }
Ok(()) Ok(())
+2 -2
View File
@@ -17,12 +17,12 @@
//! Command module responsible for handling the API Version check. //! Command module responsible for handling the API Version check.
//! //!
//! This is a minimal endpoint suitable for ensuring that the configured //! 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::config::Config;
use crate::error::ApiError; 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"; const BASE_URL: &str = "/v2";
/// Handler for the API Version Check. /// Handler for the API Version Check.
+3 -3
View File
@@ -40,7 +40,7 @@ const CONFIG_PREFIX: &str = "dredge";
/// Locate the absolute path to the saved configuration file on disk. /// Locate the absolute path to the saved configuration file on disk.
/// ///
/// If given an optional `path` to a configuration file, and that file /// 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 /// Otherwise, the XDG configuration path will be used. If neither the
/// optional `path` parameter refers to an existing file on disk, nor a /// optional `path` parameter refers to an existing file on disk, nor a
/// suitable configuration file can be located within the XDG configuration /// suitable configuration file can be located within the XDG configuration
@@ -75,7 +75,7 @@ fn locate_config_file(path: Option<OsString>) -> Option<PathBuf> {
/// ///
/// # Errors: /// # 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 /// the creation of the directory tree, or in writing the default configuration
/// to the file. /// to the file.
fn create_default_config_file() -> Result<PathBuf, ConfigError> { 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())?; let config = Config::try_from(config_file.as_ref())?;
match args.command { match args.command {
Commands::Catalog => commands::catalog::handler(&config).await?, 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?, Commands::Check => commands::version::handler(&config).await?,
} }