ocilot 0.2.3

cli and library for interacting with OCI registries
Documentation
use std::str::FromStr;

use clap::Parser;
use snafu::OptionExt;

use ocilot::error;
use ocilot::registry::Registry;
use ocilot::repository::Repository;
use ocilot::uri::RegistryUri;

use super::context::Ctx;

/// List tags in a repository.
#[derive(Parser, Debug)]
#[clap(version, about = "List the tags in a repo", long_about = None)]
pub struct List {
    url: String,
    #[arg(short, long)]
    insecure: bool,
}

impl List {
    pub async fn run(&self, _ctx: &Ctx) -> Result<(), error::Error> {
        // Split like `Uri::new` does: only the first path segment is the
        // registry, everything after it is the (possibly multi-segment)
        // repository name.
        let (registry, object) = self.url.split_once('/').context(error::MalformedUriSnafu {
            reason: "expected <registry>/<repository>",
        })?;
        let mut registry_uri = RegistryUri::from_str(registry)?;
        if self.insecure {
            registry_uri.set_secure(false);
        }
        let registry = Registry::new(&registry_uri).await?;
        let repository = Repository::new(&registry, object);
        let tags = repository.tags().await?;
        println!("{}", tags.join("\n"));
        Ok(())
    }
}