nuts_tool/cli/archive/
info.rs

1// MIT License
2//
3// Copyright (c) 2023,2024 Robin Doer
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to
7// deal in the Software without restriction, including without limitation the
8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9// sell copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21// IN THE SOFTWARE.
22
23use anyhow::Result;
24use clap::{ArgAction, Args};
25use log::debug;
26
27use crate::cli::archive::open_archive;
28use crate::say;
29use crate::time::TimeFormat;
30
31#[derive(Args, Debug)]
32pub struct ArchiveInfoArgs {
33    /// Specifies the format used for timestamps
34    #[clap(
35        short,
36        long,
37        value_parser,
38        value_name = "FORMAT",
39        default_value = "local"
40    )]
41    time_format: TimeFormat,
42
43    /// Starts the migration when the container/archive is opened
44    #[clap(long, action = ArgAction::SetTrue)]
45    pub migrate: bool,
46
47    /// Specifies the name of the container
48    #[clap(short, long, env = "NUTS_CONTAINER")]
49    container: String,
50}
51
52impl ArchiveInfoArgs {
53    pub fn run(&self) -> Result<()> {
54        debug!("args: {:?}", self);
55
56        let archive = open_archive(&self.container, self.migrate)?;
57        let info = archive.info();
58
59        let created = self.time_format.format(&info.created, "%c");
60        let modified = self.time_format.format(&info.modified, "%c");
61
62        say!("created:  {}", created);
63        say!("modified: {}", modified);
64        say!("blocks:   {}", info.blocks);
65        say!("files:    {}", info.files);
66
67        Ok(())
68    }
69}