-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcmd_search.rs
48 lines (45 loc) · 1.46 KB
/
cmd_search.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (c) Contributors to the SPK project.
// SPDX-License-Identifier: Apache-2.0
// https://github.com/spkenv/spk
use clap::Args;
use miette::Result;
use spfs::prelude::*;
use spfs::storage::fs::NoRenderStore;
use tokio_stream::StreamExt;
/// Search for available tags by substring
#[derive(Debug, Args)]
pub struct CmdSearch {
/// The search term/substring to look for
#[clap(value_name = "TERM")]
term: String,
}
impl CmdSearch {
pub async fn run(&mut self, config: &spfs::Config) -> Result<i32> {
let mut repos = Vec::with_capacity(config.remote.len());
for name in config.list_remote_names() {
let remote = match config.get_remote(&name).await {
Ok(remote) => remote,
Err(err) => {
tracing::warn!(remote = %name, "failed to load remote repository");
tracing::debug!(" > {:?}", err);
continue;
}
};
repos.push(remote);
}
repos.insert(
0,
config.get_local_repository::<NoRenderStore>().await?.into(),
);
for repo in repos.into_iter() {
let mut tag_streams = repo.iter_tags();
while let Some(tag) = tag_streams.next().await {
let (tag, _) = tag?;
if tag.to_string().contains(&self.term) {
println!("{tag:?}");
}
}
}
Ok(0)
}
}