1pub mod add;
24pub mod create;
25pub mod get;
26pub mod info;
27pub mod list;
28pub mod migrate;
29
30use anyhow::Result;
31use clap::{Args, Subcommand};
32use nuts_archive::{Archive, ArchiveFactory};
33use nuts_container::Container;
34
35use crate::backend::PluginBackend;
36use crate::cli::archive::add::ArchiveAddArgs;
37use crate::cli::archive::create::ArchiveCreateArgs;
38use crate::cli::archive::get::ArchiveGetArgs;
39use crate::cli::archive::info::ArchiveInfoArgs;
40use crate::cli::archive::list::ArchiveListArgs;
41use crate::cli::archive::migrate::ArchiveMigrateArgs;
42use crate::cli::open_container;
43
44#[derive(Debug, Args)]
45#[clap(args_conflicts_with_subcommands = true, subcommand_required = true)]
46pub struct ArchiveArgs {
47 #[clap(subcommand)]
48 command: Option<ArchiveCommand>,
49}
50
51impl ArchiveArgs {
52 pub fn run(&self) -> Result<()> {
53 self.command
54 .as_ref()
55 .map_or(Ok(()), |command| command.run())
56 }
57}
58
59#[derive(Debug, Subcommand)]
60pub enum ArchiveCommand {
61 Add(ArchiveAddArgs),
63
64 Create(ArchiveCreateArgs),
66
67 Get(ArchiveGetArgs),
69
70 Info(ArchiveInfoArgs),
72
73 List(ArchiveListArgs),
75
76 Migrate(ArchiveMigrateArgs),
78}
79
80impl ArchiveCommand {
81 pub fn run(&self) -> Result<()> {
82 match self {
83 Self::Add(args) => args.run(),
84 Self::Create(args) => args.run(),
85 Self::Get(args) => args.run(),
86 Self::Info(args) => args.run(),
87 Self::List(args) => args.run(),
88 Self::Migrate(args) => args.run(),
89 }
90 }
91}
92
93fn open_archive(name: &str, migrate: bool) -> Result<Archive<PluginBackend>> {
94 let container = open_container(name)?;
95
96 Container::open_service::<ArchiveFactory>(container, migrate).map_err(|err| err.into())
97}