asimov_cli/commands/source/snap/
create.rs1use crate::{BoxError, StandardOptions};
4use asimov_env::paths::asimov_root;
5use asimov_module::normalization::normalize_url;
6use asimov_registry::Registry;
7use asimov_snapshot::{Options, Snapshotter};
8
9pub async fn create(urls: &[String], _flags: &StandardOptions) -> Result<(), BoxError> {
10 let storage = asimov_snapshot::storage::Fs::for_dir(asimov_root().join("snapshots"))?;
11 let mut ss = Snapshotter::new(Registry::default(), storage, Options::default());
12
13 for url in urls {
14 let url = normalize_url(url).unwrap_or_else(|e| {
15 tracing::error!(
16 url,
17 "proceeding with given unmodified URL, normalization failed: {e}"
18 );
19 url.into()
20 });
21
22 ss.snapshot(&url)
23 .await
24 .inspect_err(|e| tracing::error!("failed to snapshot the resource `{url}`: {e}"))?;
25 }
26 Ok(())
27}