1use std::path::PathBuf;
2
3use clap::{Args, Parser, Subcommand, ValueEnum};
4
5#[derive(Parser, Debug, Clone)]
6#[command(author, version, about)]
7pub struct Cli {
8 #[command(subcommand)]
9 pub command: Commands,
10}
11
12#[derive(Args, Debug, Clone)]
13pub struct Create {
14 pub source: Vec<PathBuf>,
18
19 #[arg(long, short)]
23 pub archive: Option<PathBuf>,
24
25 #[arg(long, default_value = "false", overrides_with = "_no_follow")]
27 pub follow: bool,
28
29 #[arg(long = "no-follow", default_value = "true")]
31 pub _no_follow: bool,
32
33 #[arg(long = "recursive", default_value = "true")]
35 _recursive: bool,
36
37 #[arg(long, default_value = "false", overrides_with = "_recursive")]
39 pub no_recursive: bool,
40
41 #[arg(long = "preserve", default_value = "true")]
43 _preserve: bool,
44
45 #[arg(long, default_value = "false", overrides_with = "_preserve")]
47 pub no_preserve: bool,
48}
49
50#[derive(Args, Debug, Clone)]
51pub struct Extract {
52 #[arg(default_value = ".")]
54 pub dest: PathBuf,
55
56 #[arg(long, short)]
58 pub archive: PathBuf,
59
60 #[arg(short, long)]
64 pub source: Vec<PathBuf>,
65
66 #[arg(long = "recursive", default_value = "true")]
68 _recursive: bool,
69
70 #[arg(long, default_value = "false", overrides_with = "_recursive")]
72 pub no_recursive: bool,
73}
74
75#[derive(Args, Debug, Clone)]
76pub struct Archive {
77 pub source: PathBuf,
79
80 pub dest: Option<PathBuf>,
82
83 #[arg(long, short)]
85 pub archive: PathBuf,
86
87 #[arg(long, default_value = "false", overrides_with = "_no_follow")]
89 pub follow: bool,
90
91 #[arg(long = "no-follow", default_value = "true")]
93 pub _no_follow: bool,
94
95 #[arg(long = "recursive", default_value = "true")]
97 _recursive: bool,
98
99 #[arg(long, default_value = "false", overrides_with = "_recursive")]
101 pub no_recursive: bool,
102
103 #[arg(long = "preserve", default_value = "true")]
105 _preserve: bool,
106
107 #[arg(long, default_value = "false", overrides_with = "_preserve")]
109 pub no_preserve: bool,
110}
111
112#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
113pub enum FileType {
114 File,
116
117 Dir,
119
120 Symlink,
122}
123
124impl From<FileType> for sqlarfs::FileType {
125 fn from(kind: FileType) -> Self {
126 match kind {
127 FileType::File => sqlarfs::FileType::File,
128 FileType::Dir => sqlarfs::FileType::Dir,
129 FileType::Symlink => sqlarfs::FileType::Symlink,
130 }
131 }
132}
133
134#[derive(Args, Debug, Clone)]
135pub struct List {
136 pub parent: Option<PathBuf>,
138
139 #[arg(long, short)]
141 pub archive: PathBuf,
142
143 #[arg(long, default_value = "true", conflicts_with = "children")]
145 pub tree: bool,
146
147 #[arg(long, short, default_value = "false", conflicts_with = "tree")]
149 pub children: bool,
150
151 #[arg(long, short, value_enum)]
153 pub r#type: Option<FileType>,
154}
155
156#[derive(Args, Debug, Clone)]
157pub struct Remove {
158 pub path: PathBuf,
160
161 #[arg(long, short)]
163 pub archive: PathBuf,
164}
165
166#[derive(Subcommand, Debug, Clone)]
167pub enum Commands {
168 #[command(visible_alias = "c")]
170 Create(Create),
171
172 #[command(visible_alias = "ex")]
176 Extract(Extract),
177
178 #[command(visible_alias = "ar")]
180 Archive(Archive),
181
182 #[command(visible_alias = "ls")]
184 List(List),
185
186 #[command(visible_alias = "rm")]
188 Remove(Remove),
189}