Coverage Report

Created: 2024-02-20 21:15

/builds/xfbs/cindy/src/command/tags.rs
Line
Count
Source (jump to first uncovered line)
1
use crate::{
2
    cli::{TagsCommand, TagsCreateCommand, TagsDeleteCommand, TagsListCommand, TagsRenameCommand},
3
    common::tag::TagValueInfo,
4
    tag::Tag,
5
    Cindy,
6
};
7
use anyhow::Result;
8
use std::collections::BTreeMap;
9
10
impl Cindy {
11
2
    pub async fn command_tags(&self, command: &TagsCommand) -> Result<()> {
12
2
        match command {
13
1
            TagsCommand::List(command) => self.command_tags_list(command).await,
14
1
            TagsCommand::Create(command) => self.command_tags_create(command).await,
15
0
            _ => Ok(()),
16
        }
17
2
    }
18
19
0
    pub async fn command_tags_delete(&self, _command: &TagsDeleteCommand) -> Result<()> {
20
0
        todo!()
21
0
    }
22
23
0
    pub async fn command_tags_rename(&self, _command: &TagsRenameCommand) -> Result<()> {
24
0
        todo!()
25
0
    }
26
27
1
    pub async fn command_tags_create(&self, command: &TagsCreateCommand) -> Result<()> {
28
1
        let database = self.database().
await0
;
29
1
        let command = command.clone();
30
1
        tokio::task::spawn_blocking(move || {
31
3
            for 
tag2
in command.tags {
32
2
                database.tag_name_create(tag.name(), None)
?0
;
33
2
                database.tag_value_create(tag.name(), tag.value())
?0
;
34
            }
35
1
            Ok(()) as Result<()>
36
1
        })
37
1
        .await
?0
?0
;
38
1
        Ok(())
39
1
    }
40
41
1
    pub async fn command_tags_list(&self, command: &TagsListCommand) -> Result<()> {
42
1
        let database = self.database().
await0
;
43
1
        let command = command.clone();
44
1
        tokio::task::spawn_blocking(move || {
45
1
            let tags = if command.tags.is_empty() {
46
1
                database.tag_list(None, None)
?0
47
            } else {
48
0
                let results: Vec<BTreeMap<Tag, TagValueInfo>> = command
49
0
                    .tags
50
0
                    .iter()
51
0
                    .map(|filter| Ok(database.tag_list(filter.name(), filter.value())?))
52
0
                    .collect::<Result<Vec<_>>>()?;
53
0
                results.into_iter().flat_map(|i| i.into_iter()).collect()
54
            };
55
1
            for 
tag0
in tags.keys() {
56
0
                println!("{tag}");
57
0
            }
58
1
            Ok(()) as Result<()>
59
1
        })
60
1
        .await
?0
?0
;
61
1
        Ok(())
62
1
    }
63
}