dev_scripts/cli.rs
1use std::path::PathBuf;
2
3use clap::{ArgAction, Parser, ValueEnum};
4use strum::Display;
5
6use crate::sync::PackageRepositories;
7
8#[derive(Debug, Parser)]
9#[clap(name = "ALPM Dev Scripts", about = "Dev scripts for the ALPM project")]
10pub struct Cli {
11 /// Verbose mode (-v, -vv)
12 #[clap(short, long, action = ArgAction::Count)]
13 pub verbose: u8,
14
15 #[clap(subcommand)]
16 pub cmd: Command,
17}
18
19#[derive(Debug, Parser)]
20pub enum Command {
21 /// Tests file formats with real-world files from official repositories.
22 TestFiles {
23 #[clap(subcommand)]
24 cmd: TestFilesCmd,
25 },
26
27 /// Run the `alpm-pkgbuild srcinfo format` command on a PKGBUILD and compare its output with a
28 /// given .SRCINFO file.
29 CompareSrcinfo {
30 /// Path to the PKGBUILD file.
31 #[arg(
32 short,
33 long = "pkgbuild",
34 value_name = "PKGBUILD_PATH",
35 default_value = "./PKGBUILD"
36 )]
37 pkgbuild_path: PathBuf,
38
39 /// Path to the .SRCINFO file.
40 #[arg(
41 short,
42 long = "srcinfo",
43 value_name = "SRCINFO_PATH",
44 default_value = "./.SRCINFO"
45 )]
46 srcinfo_path: PathBuf,
47 },
48}
49
50#[derive(Clone, Copy, Debug, Display, Eq, Parser, PartialEq, ValueEnum)]
51pub enum TestFileType {
52 #[strum(to_string = ".BUILDINFO")]
53 BuildInfo,
54 #[strum(to_string = ".SRCINFO")]
55 SrcInfo,
56 #[strum(to_string = ".PKGINFO")]
57 PackageInfo,
58 #[strum(to_string = ".MTREE")]
59 MTree,
60 #[strum(to_string = "desc")]
61 RemoteDesc,
62 #[strum(to_string = "files")]
63 RemoteFiles,
64 #[strum(to_string = "desc")]
65 LocalDesc,
66 #[strum(to_string = "files")]
67 LocalFiles,
68}
69
70#[derive(Debug, Parser)]
71pub enum TestFilesCmd {
72 /// Download/synchronize files for testing to this machine.
73 ///
74 /// Each type of file can be downloaded individually.
75 Test {
76 // Where the local testing data is located.
77 // Defaults to `~/.cache/alpm/testing`
78 #[arg(short, long)]
79 test_data_dir: Option<PathBuf>,
80
81 /// Package repositories to test.
82 ///
83 /// If not set, all official repositories are tested.
84 #[arg(short, long)]
85 repositories: Option<Vec<PackageRepositories>>,
86
87 /// The type of file that should be tested.
88 file_type: TestFileType,
89 },
90
91 /// Download/synchronize files for testing to this machine.
92 ///
93 /// Each type of file can be downloaded individually.
94 Download {
95 // Where the testing data should be downloaded to.
96 //
97 // Defaults to `$XDG_CACHE_HOME/alpm/testing`.
98 // if `$XDG_CACHE_HOME` isn't set, it falls back to to `~/.cache/alpm/testing`.
99 #[arg(short, long)]
100 destination: Option<PathBuf>,
101
102 /// Package repositories to download.
103 ///
104 /// If not set, all official repositories are downloaded.
105 #[arg(short, long)]
106 repositories: Option<Vec<PackageRepositories>>,
107
108 #[clap(subcommand)]
109 source: DownloadCmd,
110 },
111
112 /// Remove or clean downloaded local testing files.
113 Clean {
114 // Where the testing data has been downloaded to.
115 // Defaults to `~/.cache/alpm/testing`
116 #[arg(short, long)]
117 destination: Option<PathBuf>,
118
119 #[clap(subcommand)]
120 source: CleanCmd,
121 },
122}
123
124#[derive(Debug, Parser)]
125pub enum DownloadCmd {
126 /// Download all official package source repositories
127 ///
128 /// This is done by querying all active repositories via the arch web API
129 /// (<https://archlinux.org/packages/pkgbase-maintainer>) and cloning the respective
130 /// package source repositories via git.
131 ///
132 /// This command differs from `pkgctl repo clone --universe` in so far that it
133 /// also updates git repositories and removes repositories that're no longer used.
134 ///
135 /// The repositories contain the following file types for each package.
136 /// - .SRCINFO
137 PkgSrcRepositories {},
138
139 /// Create a copy of a mirror's pacman database.
140 ///
141 /// The database contains the following file types for each package.
142 /// - `files`
143 /// - `desc`
144 Databases {
145 /// The domain + base path under which the mirror can be found.
146 ///
147 /// The mirror must support the `rsync` protocol
148 #[arg(short, long, env, default_value = "mirror.pseudoform.org/packages")]
149 mirror: String,
150
151 /// Force re-extraction of the files regardless of reported changes.
152 ///
153 /// This is useful for if the download is cancelled halfway, in which case
154 /// `rsync` will not report changes for files that it downloaded last time.
155 #[arg(short, long, default_value_t = false)]
156 force_extract: bool,
157 },
158 /// The packages contain the following file types for each package.
159 /// - `.INSTALL`
160 /// - `.BUILDINFO`
161 /// - `.MTREE`
162 /// - `.PKGINFO`
163 Packages {
164 /// The domain + base path under which the mirror can be found.
165 ///
166 /// The mirror must support the `rsync` protocol
167 #[arg(short, long, env, default_value = "mirror.pseudoform.org/packages")]
168 mirror: String,
169
170 /// Force re-extraction of the files regardless of reported changes.
171 ///
172 /// This is useful for if the download is cancelled halfway, in which case
173 /// `rsync` will not report changes for files that it downloaded last time.
174 #[arg(short, long, default_value_t = false)]
175 force_extract: bool,
176 },
177}
178
179#[derive(Debug, Parser)]
180pub enum CleanCmd {
181 /// Remove all package source repositories and .SRCINFO files
182 PkgSrcRepositories,
183
184 /// Remove extracted repository sync database files and tarballs.
185 Databases,
186
187 /// Remove all downloaded packages and any other files extracted from them.
188 Packages,
189}