From a3fff4df72737efd472a23075cee3290bd58be8a Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 11 Mar 2022 13:52:19 -0500 Subject: [PATCH] cli: Make parse functions public I want to use them in rpm-ostree too. --- lib/src/cli.rs | 9 ++++++--- lib/tests/it/main.rs | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/src/cli.rs b/lib/src/cli.rs index 8b34bb29..ad61e45b 100644 --- a/lib/src/cli.rs +++ b/lib/src/cli.rs @@ -21,15 +21,18 @@ use crate::container::store::{LayeredImageImporter, PrepareResult}; use crate::container::{self as ostree_container, UnencapsulationProgress}; use crate::container::{Config, ImageReference, OstreeImageReference, UnencapsulateOptions}; -fn parse_imgref(s: &str) -> Result { +/// Parse an [`OstreeImageReference`] from a CLI arguemnt. +pub fn parse_imgref(s: &str) -> Result { OstreeImageReference::try_from(s) } -fn parse_base_imgref(s: &str) -> Result { +/// Parse a base [`ImageReference`] from a CLI arguemnt. +pub fn parse_base_imgref(s: &str) -> Result { ImageReference::try_from(s) } -fn parse_repo(s: &str) -> Result { +/// Parse an [`ostree::Repo`] from a CLI arguemnt. +pub fn parse_repo(s: &str) -> Result { let repofd = cap_std::fs::Dir::open_ambient_dir(s, cap_std::ambient_authority())?; Ok(ostree::Repo::open_at_dir(&repofd, ".")?) } diff --git a/lib/tests/it/main.rs b/lib/tests/it/main.rs index c21aecb9..78a1f371 100644 --- a/lib/tests/it/main.rs +++ b/lib/tests/it/main.rs @@ -31,6 +31,24 @@ static TEST_REGISTRY: Lazy = Lazy::new(|| match std::env::var_os("TEST_R None => TEST_REGISTRY_DEFAULT.to_string(), }); +// This is mostly just sanity checking these functions are publicly accessible +#[test] +fn test_cli_fns() -> Result<()> { + let fixture = Fixture::new_v1()?; + let srcpath = fixture.path.join("src/repo"); + let srcrepo_parsed = ostree_ext::cli::parse_repo(srcpath.as_str()).unwrap(); + assert_eq!(srcrepo_parsed.mode(), fixture.srcrepo().mode()); + + let ir = + ostree_ext::cli::parse_imgref("ostree-unverified-registry:quay.io/examplens/exampleos") + .unwrap(); + assert_eq!(ir.imgref.transport, Transport::Registry); + + let ir = ostree_ext::cli::parse_base_imgref("docker://quay.io/examplens/exampleos").unwrap(); + assert_eq!(ir.transport, Transport::Registry); + Ok(()) +} + #[tokio::test] async fn test_tar_import_empty() -> Result<()> { let fixture = Fixture::new_v1()?;