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#[derive(Debug, Parser)]
212#[command(
213    name = "roast-scm",
214    author = "Soc Virnyl Estela",
215    about = "Create archive tarballs from remote git repositories.",
216    after_long_help = "Set verbosity and tracing through `RUST_LOG` environmental variable e.g. \
217                       `RUST_LOG=trace`",
218    help_template = "{name} {version} - \
219                     {about}\n\n{usage}\n\n{all-args}\n{after-help}\nMaintained by {author} \
220                     <contact@uncomfyhalomacro.pl>.",
221    version
222)]
223pub struct RoastScmArgs
224{
225    #[arg(long, short = 'g', help = "Remote URL to the git repository.", alias = "url")]
226    pub git_repository_url: String,
227    #[arg(
228        long,
229        short = 'E',
230        help = "Additional paths such as files or directories from within target repository's \
231                work directory to exclude when generating the archive."
232    )]
233    pub exclude: Option<Vec<PathBuf>>,
234    #[arg(long, help = "Revision or tag. It can also be a specific commit hash.")]
235    pub revision: String,
236    #[arg(
237        long, default_value_t = 1,
238        action = clap::ArgAction::Set,
239        help = "The depth of cloning the repository.")]
240    pub depth: i32,
241    #[arg(
242        long, default_value_t = true,
243        action = clap::ArgAction::Set,
244        help = "If the cloned repository should be temporary."
245    )]
246    pub is_temporary: bool,
247    #[arg(
248        long,
249        short = 'f',
250        help = "Output file of the generated archive with path. If not provided, attempts to \
251                write the filename based on project name and revision."
252    )]
253    pub outfile: Option<PathBuf>,
254    #[arg(long, short = 'd', help = "Output path of the generated archive.")]
255    pub outdir: Option<PathBuf>,
256    #[arg(
257        long,
258        short = 'r',
259        help = "Allow reproducibility for Reproducible Builds.",
260        default_value_t = false,
261        action = clap::ArgAction::Set
262    )]
263    pub reproducible: bool,
264    #[arg(
265        long,
266        short = 'g',
267        help = "Whether to ignore git related metadata, files and directories.",
268        default_value_t = true,
269        action = clap::ArgAction::Set
270    )]
271    pub ignore_git: bool,
272    #[arg(
273        long,
274        short = 'I',
275        help = "Whether to ignore hidden directories and files or what we call dotfiles. Does not affect `--ignore-git`.",
276        default_value_t = false,
277        action = clap::ArgAction::Set
278    )]
279    pub ignore_hidden: bool,
280    #[arg(long, short = 'c', help = "Compression to use.", default_value_t)]
281    pub compression: Compression,
282}