Skip to main content

rustic_rs/commands/
tag.rs

1//! `tag` subcommand
2use abscissa_core::{Command, Runnable};
3use rustic_core::{StringList, repofile::SnapshotModification};
4
5use crate::commands::rewrite::RewriteCmd;
6
7/// `tag` subcommand
8#[derive(clap::Parser, Command, Debug)]
9pub(crate) struct TagCmd {
10    /// Snapshots to change tags. If none is given, use filter to filter from all snapshots
11    ///
12    /// Snapshots can be identified the following ways: "01a2b3c4" or "latest" or "latest~N" (N >= 0)
13    #[clap(value_name = "ID")]
14    ids: Vec<String>,
15
16    /// Tags to add (can be specified multiple times)
17    #[clap(
18        long,
19        value_name = "TAG[,TAG,..]",
20        conflicts_with = "remove",
21        help_heading = "Tag options"
22    )]
23    add: Vec<StringList>,
24
25    /// Tags to remove (can be specified multiple times)
26    #[clap(long, value_name = "TAG[,TAG,..]", help_heading = "Tag options")]
27    remove: Vec<StringList>,
28
29    /// Tag list to set (can be specified multiple times)
30    #[clap(
31        long,
32        value_name = "TAG[,TAG,..]",
33        conflicts_with = "remove",
34        help_heading = "Tag options"
35    )]
36    set: Vec<StringList>,
37}
38
39impl Runnable for TagCmd {
40    fn run(&self) {
41        let modification = SnapshotModification::default()
42            .add_tags(self.add.clone())
43            .remove_tags(self.remove.clone())
44            .set_tags(self.set.clone());
45        let rewrite = RewriteCmd {
46            ids: self.ids.clone(),
47            modification,
48            forget: true,
49            ..Default::default()
50        };
51        rewrite.run();
52    }
53}