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(Parser, Debug)]
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(Parser, Debug)]
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
28#[derive(Parser, ValueEnum, Display, Debug, Clone, Copy, PartialEq, Eq)]
29pub enum TestFileType {
30 #[strum(to_string = ".BUILDINFO")]
31 BuildInfo,
32 #[strum(to_string = ".SRCINFO")]
33 SrcInfo,
34 #[strum(to_string = ".PKGINFO")]
35 PackageInfo,
36 #[strum(to_string = ".MTREE")]
37 MTree,
38 #[strum(to_string = "desc")]
39 RemoteDesc,
40 #[strum(to_string = "files")]
41 RemoteFiles,
42 #[strum(to_string = "desc")]
43 LocalDesc,
44 #[strum(to_string = "files")]
45 LocalFiles,
46}
47
48#[derive(Parser, Debug)]
49pub enum TestFilesCmd {
50 /// Download/synchronize files for testing to this machine.
51 ///
52 /// Each type of file can be downloaded individually.
53 Test {
54 // Where the local testing data is located.
55 // Defaults to `~/.cache/alpm/testing`
56 #[arg(short, long)]
57 test_data_dir: Option<PathBuf>,
58
59 /// Package repositories to test.
60 ///
61 /// If not set, all official repositories are tested.
62 #[arg(short, long)]
63 repositories: Option<Vec<PackageRepositories>>,
64
65 /// The type of file that should be tested.
66 file_type: TestFileType,
67 },
68
69 /// Download/synchronize files for testing to this machine.
70 ///
71 /// Each type of file can be downloaded individually.
72 Download {
73 // Where the testing data should be downloaded to.
74 //
75 // Defaults to `$XDG_CACHE_HOME/alpm/testing`.
76 // if `$XDG_CACHE_HOME` isn't set, it falls back to to `~/.cache/alpm/testing`.
77 #[arg(short, long)]
78 destination: Option<PathBuf>,
79
80 /// Package repositories to download.
81 ///
82 /// If not set, all official repositories are downloaded.
83 #[arg(short, long)]
84 repositories: Option<Vec<PackageRepositories>>,
85
86 #[clap(subcommand)]
87 source: DownloadCmd,
88 },
89
90 /// Remove or clean downloaded local testing files.
91 Clean {
92 // Where the testing data has been downloaded to.
93 // Defaults to `~/.cache/alpm/testing`
94 #[arg(short, long)]
95 destination: Option<PathBuf>,
96
97 #[clap(subcommand)]
98 source: CleanCmd,
99 },
100}
101
102#[derive(Parser, Debug)]
103pub enum DownloadCmd {
104 /// Download all official package source repositories
105 ///
106 /// This is done by querying all active repositories via the arch web API
107 /// (<https://archlinux.org/packages/pkgbase-maintainer>) and cloning the respective
108 /// package source repositories via git.
109 ///
110 /// This command differs from `pkgctl repo clone --universe` in so far that it
111 /// also updates git repositories and removes repositories that're no longer used.
112 ///
113 /// The repositories contain the following file types for each package.
114 /// - .SRCINFO
115 PkgSrcRepositories {},
116
117 /// Create a copy of a mirror's pacman database.
118 ///
119 /// The database contains the following file types for each package.
120 /// - `files`
121 /// - `desc`
122 Databases {
123 /// The domain + base path under which the mirror can be found.
124 ///
125 /// The mirror must support the `rsync` protocol
126 #[arg(short, long, env, default_value = "mirror.pseudoform.org/packages")]
127 mirror: String,
128 },
129 /// The packages contain the following file types for each package.
130 /// - `.INSTALL`
131 /// - `.BUILDINFO`
132 /// - `.MTREE`
133 /// - `.PKGINFO`
134 Packages {
135 /// The domain + base path under which the mirror can be found.
136 ///
137 /// The mirror must support the `rsync` protocol
138 #[arg(short, long, env, default_value = "mirror.pseudoform.org/packages")]
139 mirror: String,
140 },
141}
142
143#[derive(Parser, Debug)]
144pub enum CleanCmd {
145 /// Remove all package source repositories and .SRCINFO files
146 PkgSrcRepositories,
147
148 /// Remove extracted repository sync database files and tarballs.
149 Databases,
150
151 /// Remove all downloaded packages and any other files extracted from them.
152 Packages,
153}