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 = "Use this flag if you want a new filename to use ignoring the new file extension. \
182                Omitting this flag will just fallback to basename."
183    )]
184    pub rename: Option<String>,
185    #[arg(
186        long,
187        short = 'r',
188        help = "Allow reproducibility for Reproducible Builds.",
189        default_value_t = false,
190        action = clap::ArgAction::Set
191    )]
192    pub reproducible: bool,
193    #[arg(
194        long,
195        short = 'g',
196        help = "Whether to ignore git related metadata, files and directories.",
197        default_value_t = true,
198        action = clap::ArgAction::Set
199    )]
200    pub ignore_git: bool,
201    #[arg(
202        long,
203        short = 'I',
204        help = "Whether to ignore hidden directories and files or what we call dotfiles. Does not affect `--ignore-git`.",
205        default_value_t = false,
206        action = clap::ArgAction::Set
207    )]
208    pub ignore_hidden: bool,
209}
210
211#[cfg(not(feature = "obs"))]
212#[derive(Debug, Parser)]
213#[command(
214    name = "roast-scm",
215    author = "Soc Virnyl Estela",
216    about = "Create archive tarballs from remote git repositories.",
217    after_long_help = "Set verbosity and tracing through `RUST_LOG` environmental variable e.g. \
218                       `RUST_LOG=trace`",
219    help_template = "{name} {version} - \
220                     {about}\n\n{usage}\n\n{all-args}\n{after-help}\nMaintained by {author} \
221                     <contact@uncomfyhalomacro.pl>.",
222    version
223)]
224pub struct RoastScmArgs
225{
226    #[arg(long, short = 'C', action = clap::ArgAction::Set, default_value_t = false, help = "Whether to generate or update a changelog file or not.")]
227    pub changesgenerate: bool,
228    #[arg(
229        long,
230        short = 'A',
231        requires_if("changesgenerate", "true"),
232        help = "Author to include during the changelog generation."
233    )]
234    pub changesauthor: Option<String>,
235    #[arg(long, short = 'e', help = "Email of author to include during the changelog generation.")]
236    pub changesemail: Option<String>,
237    #[arg(
238        long,
239        alias = "caof",
240        requires_if("changesgenerate", "true"),
241        help = "Whether to specify a path to the changes file. Otherwise, it is the current \
242                directory and the filename is the same filename prefix of the generated tarball \
243                e.g. `source.tar.xz` will have `source.changes` file. If file exists, append the \
244                newest changes to the top-most part of the text file."
245    )]
246    pub changesoutfile: Option<PathBuf>,
247    #[arg(long, short = 'U', help = "Remote URL to the git repository.", alias = "url")]
248    pub git_repository_url: String,
249    #[arg(
250        long,
251        short = 'E',
252        help = "Additional paths such as files or directories from within target repository's \
253                work directory to exclude when generating the archive."
254    )]
255    pub exclude: Option<Vec<PathBuf>>,
256    #[arg(
257        long,
258        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>."
259    )]
260    pub revision: String,
261    #[arg(
262        long,
263        help = "Pass a regex with capture groups. Required by `versionrewritepattern` flag. Each \
264                capture group is labelled through increments of 1.",
265        requires = "versionrewritepattern"
266    )]
267    pub versionrewriteregex: Option<String>,
268    #[arg(long, help = "Pass a pattern from the capture groups from `versionrewriteregex` flag.")]
269    pub versionrewritepattern: Option<String>,
270    #[arg(
271        long, default_value_t = 0,
272        action = clap::ArgAction::Set,
273        help = "The depth of cloning the repository.")]
274    pub depth: i32,
275    #[arg(
276        long, default_value_t = true,
277        action = clap::ArgAction::Set,
278        help = "Whether the cloned repository should be deleted or not after the operation."
279    )]
280    pub is_temporary: bool,
281    #[arg(
282        long,
283        short = 'f',
284        help = "Output file of the generated archive with path. If not provided, attempts to \
285                write the filename based on project name and revision based on <https://en.opensuse.org/openSUSE:Package_versioning_guidelines>."
286    )]
287    pub outfile: Option<PathBuf>,
288    #[arg(long, short = 'd', help = "Output path of the generated archive.")]
289    pub outdir: Option<PathBuf>,
290    #[arg(
291        long,
292        short = 'r',
293        help = "Allow reproducibility for Reproducible Builds.",
294        default_value_t = false,
295        action = clap::ArgAction::Set
296    )]
297    pub reproducible: bool,
298    #[arg(
299        long,
300        short = 'g',
301        help = "Whether to ignore git related metadata, files and directories.",
302        default_value_t = true,
303        action = clap::ArgAction::Set
304    )]
305    pub ignore_git: bool,
306    #[arg(
307        long,
308        short = 'I',
309        help = "Whether to ignore hidden directories and files or what we call dotfiles. Does not affect `--ignore-git`.",
310        default_value_t = false,
311        action = clap::ArgAction::Set
312    )]
313    pub ignore_hidden: bool,
314    #[arg(long, short = 'c', help = "Compression to use.", default_value_t)]
315    pub compression: Compression,
316}
317
318#[cfg(feature = "obs")]
319#[derive(Debug, Parser)]
320#[command(
321    name = "roast-scm",
322    author = "Soc Virnyl Estela",
323    about = "Create archive tarballs from remote git repositories.",
324    after_long_help = "Set verbosity and tracing through `RUST_LOG` environmental variable e.g. \
325                       `RUST_LOG=trace`",
326    help_template = "{name} {version} - \
327                     {about}\n\n{usage}\n\n{all-args}\n{after-help}\nMaintained by {author} \
328                     <contact@uncomfyhalomacro.pl>.",
329    version
330)]
331pub struct RoastScmArgs
332{
333    #[arg(long, short = 'C', action = clap::ArgAction::Set, default_value_t = false, help = "Whether to generate or update a changelog file or not.")]
334    pub changesgenerate: bool,
335    #[arg(
336        long,
337        short = 'A',
338        requires_if("changesgenerate", "true"),
339        help = "Author to include during the changelog generation."
340    )]
341    pub changesauthor: Option<String>,
342    #[arg(long, short = 'e', help = "Email of author to include during the changelog generation.")]
343    pub changesemail: Option<String>,
344    #[arg(
345        long,
346        alias = "caof",
347        requires_if("changesgenerate", "true"),
348        help = "Whether to specify a path to the changes file. Otherwise, it is the current \
349                directory and the filename is the same filename prefix of the generated tarball \
350                e.g. `source.tar.xz` will have `source.changes` file. If file exists, append the \
351                newest changes to the top-most part of the text file."
352    )]
353    pub changesoutfile: Option<PathBuf>,
354    #[arg(
355        long,
356        help = "Whether to hard code the version or not. Set it to hard code one, otherwise, it \
357                will use the generated version internally."
358    )]
359    pub set_version: Option<String>,
360    #[arg(
361        long,
362        help = "Whether to hard code the name or not. Set it to hard code one, otherwise, it will \
363                use the generated name internally."
364    )]
365    pub set_name: Option<String>,
366    #[arg(long, short = 'U', help = "Remote URL to the git repository.", alias = "url")]
367    pub git_repository_url: String,
368    #[arg(
369        long,
370        short = 'E',
371        help = "Additional paths such as files or directories from within target repository's \
372                work directory to exclude when generating the archive."
373    )]
374    pub exclude: Option<Vec<PathBuf>>,
375    #[arg(
376        long,
377        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>."
378    )]
379    pub revision: String,
380    #[arg(
381        long,
382        help = "Pass a regex with capture groups. Required by `versionrewritepattern` flag. Each \
383                capture group is labelled through increments of 1.",
384        requires = "versionrewritepattern"
385    )]
386    pub versionrewriteregex: Option<String>,
387    #[arg(long, help = "Pass a pattern from the capture groups from `versionrewriteregex` flag.")]
388    pub versionrewritepattern: Option<String>,
389    #[arg(
390        long, default_value_t = 0,
391        action = clap::ArgAction::Set,
392        help = "The depth of cloning the repository.")]
393    pub depth: i32,
394    #[arg(
395        long, default_value_t = true,
396        action = clap::ArgAction::Set,
397        help = "Whether the cloned repository should be deleted or not after the operation."
398    )]
399    pub is_temporary: bool,
400    #[arg(
401        long,
402        short = 'f',
403        help = "Output file of the generated archive with path. If not provided, attempts to \
404                write the filename based on project name and revision based on <https://en.opensuse.org/openSUSE:Package_versioning_guidelines>."
405    )]
406    pub outfile: Option<PathBuf>,
407    #[arg(long, short = 'd', help = "Output path of the generated archive.")]
408    pub outdir: Option<PathBuf>,
409    #[arg(
410        long,
411        short = 'r',
412        help = "Allow reproducibility for Reproducible Builds.",
413        default_value_t = false,
414        action = clap::ArgAction::Set
415    )]
416    pub reproducible: bool,
417    #[arg(
418        long,
419        short = 'g',
420        help = "Whether to ignore git related metadata, files and directories.",
421        default_value_t = true,
422        action = clap::ArgAction::Set
423    )]
424    pub ignore_git: bool,
425    #[arg(
426        long,
427        short = 'I',
428        help = "Whether to ignore hidden directories and files or what we call dotfiles. Does not affect `--ignore-git`.",
429        default_value_t = false,
430        action = clap::ArgAction::Set
431    )]
432    pub ignore_hidden: bool,
433    #[arg(long, short = 'c', help = "Compression to use.", default_value_t)]
434    pub compression: Compression,
435}