libroast/operations/
cli.rs

1//! Mostly structs that are used for `clap` for CLI arguments.
2//! Also useful for just anything else not CLI.
3
4use crate::common::Compression;
5use clap::Parser;
6use std::path::PathBuf;
7#[allow(unused_imports)]
8use tracing::{
9    Level,
10    debug,
11    error,
12    info,
13    trace,
14    warn,
15};
16
17#[derive(Debug, Parser)]
18#[command(
19    name = "roast",
20    author = "Soc Virnyl Estela",
21    about = "Archiver with high-level compression",
22    after_long_help = "Set verbosity and tracing through `RUST_LOG` environmental variable e.g. \
23                       `RUST_LOG=trace`",
24    help_template = "{name} {version} - \
25                     {about}\n\n{usage}\n\n{all-args}\n{after-help}\nMaintained by {author} \
26                     <contact@uncomfyhalomacro.pl>.",
27    version
28)]
29pub struct RoastArgs
30{
31    #[arg(
32        long,
33        short = 't',
34        help = "Target directory to archive. This will be set as the root directory of the \
35                archive. Supports globbing."
36    )]
37    pub target: PathBuf,
38    #[arg(
39        long,
40        short = 'i',
41        help = "Additional paths such as files or directories in the target directory to include \
42                to the archive. Their parent directory will be put next to the target directory's \
43                work directory. The work directory is based on the preserve root option. This is \
44                different from `--additional_paths`. Useful to override excluded directories. ⚠️ \
45                Careful if the archive has whether preserved root set when it was created."
46    )]
47    pub include: Option<Vec<PathBuf>>,
48    #[arg(
49        long,
50        short = 'E',
51        help = "Additional paths such as files or directories from within target directory's work \
52                directory to exclude when generating the archive."
53    )]
54    pub exclude: Option<Vec<PathBuf>>,
55    #[arg(
56        long,
57        short = 'A',
58        help = "Additional paths such as files or directories to add to the archive. Their parent \
59                directory will be put next to the target directory. This is different from \
60                `--include`. Optionally, one can add a path to a directory inside the archive \
61                e.g. `-A some/file/to/archive,put/where/in/archive`. If directory does not exist, \
62                it will be created."
63    )]
64    pub additional_paths: Option<Vec<String>>,
65    #[arg(long, short = 'f', help = "Output file of the generated archive with path.")]
66    pub outfile: PathBuf,
67    #[arg(long, short = 'd', help = "Output path of the generated archive.")]
68    pub outdir: Option<PathBuf>,
69    #[arg(
70        long,
71        short = 'p',
72        help = "Preserve root directory instead of only archiving relative paths.",
73        default_value_t = false,
74        action = clap::ArgAction::Set
75    )]
76    pub preserve_root: bool,
77    #[arg(
78        long,
79        short = 'r',
80        help = "Allow reproducibility for Reproducible Builds.",
81        default_value_t = false,
82        action = clap::ArgAction::Set
83    )]
84    pub reproducible: bool,
85    #[arg(
86        long,
87        short = 'g',
88        help = "Whether to ignore git related metadata, files and directories.",
89        default_value_t = true,
90        action = clap::ArgAction::Set
91    )]
92    pub ignore_git: bool,
93    #[arg(
94        long,
95        short = 'I',
96        help = "Whether to ignore hidden directories and files or what we call dotfiles. Does not affect `--ignore-git`.",
97        default_value_t = false,
98        action = clap::ArgAction::Set
99    )]
100    pub ignore_hidden: bool,
101}
102
103#[derive(Debug, Parser)]
104#[command(
105    name = "raw",
106    author = "Soc Virnyl Estela",
107    about = "Raw extractor and decompressor",
108    after_long_help = "Set verbosity and tracing through `RUST_LOG` environmental variable e.g. \
109                       `RUST_LOG=trace`",
110    help_template = "{name} {version} - \
111                     {about}\n\n{usage}\n\n{all-args}\n{after-help}\nMaintained by {author} \
112                     <contact@uncomfyhalomacro.pl>.",
113    version
114)]
115pub struct RawArgs
116{
117    #[arg(
118        long,
119        short = 't',
120        help = "Target tarball file to extract and decompress. Supports globbing."
121    )]
122    pub target: PathBuf,
123    #[arg(long, short = 'd', help = "Output directory of extracted archive.")]
124    pub outdir: Option<PathBuf>,
125}
126
127#[derive(Debug, Parser)]
128#[command(
129    name = "recomprizz",
130    author = "Soc Virnyl Estela",
131    about = "Recompress to other compression formats",
132    after_long_help = "Set verbosity and tracing through `RUST_LOG` environmental variable e.g. \
133                       `RUST_LOG=trace`",
134    help_template = "{name} {version} - \
135                     {about}\n\n{usage}\n\n{all-args}\n{after-help}\nMaintained by {author} \
136                     <contact@uncomfyhalomacro.pl>.",
137    version
138)]
139pub struct RecomprizzArgs
140{
141    #[arg(
142        long,
143        short = 't',
144        help = "Target tarball file to extract and recompress. Supports globbing."
145    )]
146    pub target: PathBuf,
147    #[arg(
148        long,
149        short = 'i',
150        help = "Additional paths such as files or directories in the target directory to include \
151                to the archive. Their parent directory will be put next to the target directory's \
152                work directory. The work directory is based on the preserve root option. This is \
153                different from `--additional_paths`. Useful to override excluded directories."
154    )]
155    pub include: Option<Vec<PathBuf>>,
156    #[arg(
157        long,
158        short = 'E',
159        help = "Additional paths such as files or directories from within target directory's work \
160                directory to exclude when generating the archive. ⚠️ Careful if the archive has \
161                whether preserved root set when it was created."
162    )]
163    pub exclude: Option<Vec<PathBuf>>,
164    #[arg(
165        long,
166        short = 'A',
167        help = "Additional paths such as files or directories to add to the archive. Their parent \
168                directory will be put next to the target directory. This is different from \
169                `--include`. Optionally, one can add a path to a directory inside the archive \
170                e.g. `-A some/file/to/archive,put/where/in/archive`. If directory does not exist, \
171                it will be created."
172    )]
173    pub additional_paths: Option<Vec<String>>,
174    #[arg(long, short = 'd', help = "Output directory of recompressed archive.")]
175    pub outdir: Option<PathBuf>,
176    #[arg(long, short = 'c', help = "Compression to use.", default_value_t)]
177    pub compression: Compression,
178    #[arg(
179        long,
180        short = 'R',
181        help = "Pass a string or regex value into this flag. This will be used with the \
182                `--renamepattern` flag. If no value is provided to `--renamepattern`, this is \
183                assumed to be a hard-coded name."
184    )]
185    pub rename: Option<String>,
186    #[arg(
187        long,
188        requires = "rename",
189        help = "Pass a replacement pattern using the capture groups into this flag. This will be \
190                used with the `--rename` flag."
191    )]
192    pub renamepattern: Option<String>,
193    #[arg(
194        long,
195        short = 'r',
196        help = "Allow reproducibility for Reproducible Builds.",
197        default_value_t = false,
198        action = clap::ArgAction::Set
199    )]
200    pub reproducible: bool,
201    #[arg(
202        long,
203        short = 'g',
204        help = "Whether to ignore git related metadata, files and directories.",
205        default_value_t = true,
206        action = clap::ArgAction::Set
207    )]
208    pub ignore_git: bool,
209    #[arg(
210        long,
211        short = 'I',
212        help = "Whether to ignore hidden directories and files or what we call dotfiles. Does not affect `--ignore-git`.",
213        default_value_t = false,
214        action = clap::ArgAction::Set
215    )]
216    pub ignore_hidden: bool,
217}
218
219#[derive(Debug, Parser)]
220#[command(
221    name = "roast-scm",
222    author = "Soc Virnyl Estela",
223    about = "Create archive tarballs from remote git repositories.",
224    after_long_help = "Set verbosity and tracing through `RUST_LOG` environmental variable e.g. \
225                       `RUST_LOG=trace`",
226    help_template = "{name} {version} - \
227                     {about}\n\n{usage}\n\n{all-args}\n{after-help}\nMaintained by {author} \
228                     <contact@uncomfyhalomacro.pl>.",
229    version
230)]
231pub struct RoastScmArgs
232{
233    #[arg(long, requires_if("true", "changesauthor"), short = 'C', action = clap::ArgAction::Set, default_value_t = false, help = "Whether to generate or update a changelog file or not.")]
234    pub changesgenerate: bool,
235    #[arg(
236        long,
237        short = 'A',
238        requires = "changesgenerate",
239        help = "Author to include during the changelog generation."
240    )]
241    pub changesauthor: Option<String>,
242    #[arg(
243        long,
244        requires = "changesauthor",
245        short = 'e',
246        help = "Email of author to include during the changelog generation."
247    )]
248    pub changesemail: Option<String>,
249    #[arg(
250        long,
251        alias = "caof",
252        help = "Whether to specify a path to the changes file. Otherwise, it is the current \
253                directory and the filename is the same filename prefix of the generated tarball \
254                e.g. `source.tar.xz` will have `source.changes` file. If file exists, it prepends \
255                the newest changes to the top-most part of the text file."
256    )]
257    pub changesoutfile: Option<PathBuf>,
258    #[arg(
259        long,
260        help = "Whether to hard code the version or not. Set it to hard code one, otherwise, it \
261                will use the generated version internally."
262    )]
263    pub set_version: Option<String>,
264    #[arg(
265        long,
266        help = "Whether to hard code the name or not. Set it to hard code one, otherwise, it will \
267                use the generated name internally."
268    )]
269    pub set_name: Option<String>,
270    #[arg(long, short = 'U', help = "Remote URL to the git repository.", alias = "url")]
271    pub git_repository_url: String,
272    #[arg(
273        long,
274        short = 'E',
275        help = "Additional paths such as files or directories from within target repository's \
276                work directory to exclude when generating the archive."
277    )]
278    pub exclude: Option<Vec<PathBuf>>,
279    #[arg(
280        long,
281        help = "Revision or tag. It can also be a specific commit hash or branch. Supports <https://git-scm.com/docs/git-rev-parse.html#_specifying_revisions>."
282    )]
283    pub revision: String,
284    #[arg(
285        long,
286        help = "Pass a regex with capture groups. Required by `versionrewritepattern` flag. Each \
287                capture group is labelled through increments of 1.",
288        requires = "versionrewritepattern"
289    )]
290    pub versionrewriteregex: Option<String>,
291    #[arg(long, help = "Pass a pattern from the capture groups from `versionrewriteregex` flag.")]
292    pub versionrewritepattern: Option<String>,
293    #[arg(
294        long, default_value_t = 0,
295        action = clap::ArgAction::Set,
296        help = "The depth of cloning the repository.")]
297    pub depth: i32,
298    #[arg(
299        long, default_value_t = true,
300        action = clap::ArgAction::Set,
301        help = "Whether the cloned repository should be deleted or not after the operation."
302    )]
303    pub is_temporary: bool,
304    #[arg(
305        long,
306        short = 'f',
307        help = "Output file of the generated archive with path. If not provided, attempts to \
308                write the filename based on project name and revision based on <https://en.opensuse.org/openSUSE:Package_versioning_guidelines>."
309    )]
310    pub outfile: Option<PathBuf>,
311    #[arg(long, short = 'd', help = "Output path of the generated archive.")]
312    pub outdir: Option<PathBuf>,
313    #[arg(
314        long,
315        short = 'r',
316        help = "Allow reproducibility for Reproducible Builds.",
317        default_value_t = false,
318        action = clap::ArgAction::Set
319    )]
320    pub reproducible: bool,
321    #[arg(
322        long,
323        short = 'g',
324        help = "Whether to ignore git related metadata, files and directories.",
325        default_value_t = true,
326        action = clap::ArgAction::Set
327    )]
328    pub ignore_git: bool,
329    #[arg(
330        long,
331        short = 'I',
332        help = "Whether to ignore hidden directories and files or what we call dotfiles. Does not affect `--ignore-git`.",
333        default_value_t = false,
334        action = clap::ArgAction::Set
335    )]
336    pub ignore_hidden: bool,
337    #[arg(long, short = 'c', help = "Compression to use.", default_value_t)]
338    pub compression: Compression,
339}