Skip to main content

steamroom_cli/daemon/proto/
params.rs

1//! Per-command argument shadows of the clap-derived structs in `cli.rs`.
2//! These are rkyv-archivable: `PathBuf` becomes `String`, `Regex` becomes
3//! a raw pattern string, clap enums become their wire mirrors.
4
5use super::OutputFormat;
6use rkyv::Archive;
7use rkyv::Deserialize;
8use rkyv::Serialize;
9
10#[derive(Archive, Serialize, Deserialize, Debug, Clone)]
11#[rkyv(derive(Debug))]
12pub struct DownloadParams {
13    pub app: u32,
14    pub depot: Option<u32>,
15    pub manifest: Option<u64>,
16    pub filelist: Option<String>,
17    pub file_regex: Option<String>,
18    pub output: Option<String>,
19    pub verify: bool,
20    pub os: Option<String>,
21    pub arch: Option<String>,
22    pub language: Option<String>,
23    pub login_id: Option<u32>,
24    pub all_platforms: bool,
25    pub all_architectures: bool,
26    pub all_languages: bool,
27    pub lancache: bool,
28    pub max_downloads: Option<u32>,
29    pub branch: Option<String>,
30    pub branch_password: Option<String>,
31    pub local_keys: bool,
32    pub non_atomic: bool,
33    pub save_manifests: bool,
34    pub bytes: bool,
35}
36
37#[derive(Archive, Serialize, Deserialize, Debug, Clone)]
38#[rkyv(derive(Debug))]
39pub struct InfoParams {
40    pub app: u32,
41    pub format: Option<OutputFormat>,
42    pub os: Option<String>,
43    pub show_all: bool,
44}
45
46#[derive(Archive, Serialize, Deserialize, Debug, Clone)]
47#[rkyv(derive(Debug))]
48pub struct FilesParams {
49    pub app: Option<u32>,
50    pub depot: Option<u32>,
51    pub manifest: Option<u64>,
52    pub manifest_file: Option<String>,
53    pub depot_key: Option<String>,
54    pub branch: Option<String>,
55    pub branch_password: Option<String>,
56    pub os: Option<String>,
57    pub format: Option<OutputFormat>,
58    pub raw: bool,
59    pub bytes: bool,
60}
61
62#[derive(Archive, Serialize, Deserialize, Debug, Clone)]
63#[rkyv(derive(Debug))]
64pub struct ManifestsParams {
65    pub app: u32,
66    pub branch: Option<String>,
67    pub branch_password: Option<String>,
68    pub format: Option<OutputFormat>,
69}
70
71#[derive(Archive, Serialize, Deserialize, Debug, Clone)]
72#[rkyv(derive(Debug))]
73pub struct DiffParams {
74    pub app: u32,
75    pub depot: u32,
76    pub from: u64,
77    pub to: u64,
78    pub branch: Option<String>,
79    pub format: Option<OutputFormat>,
80}
81
82#[derive(Archive, Serialize, Deserialize, Debug, Clone)]
83#[rkyv(derive(Debug))]
84pub struct PackagesParams {
85    pub packages: Vec<u32>,
86    pub format: Option<OutputFormat>,
87}
88
89#[derive(Archive, Serialize, Deserialize, Debug, Clone)]
90#[rkyv(derive(Debug))]
91pub struct SaveManifestParams {
92    pub app: u32,
93    pub depot: u32,
94    pub manifest: Option<u64>,
95    pub branch: Option<String>,
96    pub output: String,
97}
98
99#[derive(Archive, Serialize, Deserialize, Debug, Clone)]
100#[rkyv(derive(Debug))]
101pub struct WorkshopParams {
102    pub app: u32,
103    pub item: u64,
104    pub output: Option<String>,
105}
106
107#[derive(Archive, Serialize, Deserialize, Debug, Clone)]
108#[rkyv(derive(Debug))]
109pub struct LocalInfoParams {
110    pub format: Option<OutputFormat>,
111    pub user: Option<String>,
112    pub users: bool,
113}
114
115fn pathbuf_to_string(p: std::path::PathBuf) -> String {
116    p.to_string_lossy().into_owned()
117}
118
119impl From<crate::cli::DownloadArgs> for DownloadParams {
120    fn from(a: crate::cli::DownloadArgs) -> Self {
121        Self {
122            app: a.app,
123            depot: a.depot,
124            manifest: a.manifest,
125            filelist: a.filelist.map(pathbuf_to_string),
126            file_regex: a.file_regex,
127            output: a.output.map(pathbuf_to_string),
128            verify: a.verify,
129            os: a.os,
130            arch: a.arch,
131            language: a.language,
132            login_id: a.login_id,
133            all_platforms: a.all_platforms,
134            all_architectures: a.all_architectures,
135            all_languages: a.all_languages,
136            lancache: a.lancache,
137            // Saturate at u32::MAX: real CDN parallelism caps are far below this.
138            max_downloads: a
139                .max_downloads
140                .map(|n| u32::try_from(n).unwrap_or(u32::MAX)),
141            branch: a.branch,
142            branch_password: a.branch_password,
143            local_keys: a.local_keys,
144            non_atomic: a.non_atomic,
145            save_manifests: a.save_manifests,
146            bytes: a.bytes,
147        }
148    }
149}
150
151impl From<crate::cli::InfoArgs> for InfoParams {
152    fn from(a: crate::cli::InfoArgs) -> Self {
153        Self {
154            app: a.app,
155            format: a.format.map(Into::into),
156            os: a.os,
157            show_all: a.show_all,
158        }
159    }
160}
161
162impl From<crate::cli::FilesArgs> for FilesParams {
163    fn from(a: crate::cli::FilesArgs) -> Self {
164        Self {
165            app: a.app,
166            depot: a.depot,
167            manifest: a.manifest,
168            manifest_file: a.manifest_file.map(pathbuf_to_string),
169            depot_key: a.depot_key,
170            branch: a.branch,
171            branch_password: a.branch_password,
172            os: a.os,
173            format: a.format.map(Into::into),
174            raw: a.raw,
175            bytes: a.bytes,
176        }
177    }
178}
179
180impl From<crate::cli::ManifestsArgs> for ManifestsParams {
181    fn from(a: crate::cli::ManifestsArgs) -> Self {
182        Self {
183            app: a.app,
184            branch: a.branch,
185            branch_password: a.branch_password,
186            format: a.format.map(Into::into),
187        }
188    }
189}
190
191impl From<crate::cli::DiffArgs> for DiffParams {
192    fn from(a: crate::cli::DiffArgs) -> Self {
193        Self {
194            app: a.app,
195            depot: a.depot,
196            from: a.from,
197            to: a.to,
198            branch: a.branch,
199            format: a.format.map(Into::into),
200        }
201    }
202}
203
204impl From<crate::cli::PackagesArgs> for PackagesParams {
205    fn from(a: crate::cli::PackagesArgs) -> Self {
206        Self {
207            packages: a.packages,
208            format: a.format.map(Into::into),
209        }
210    }
211}
212
213impl From<crate::cli::SaveManifestArgs> for SaveManifestParams {
214    fn from(a: crate::cli::SaveManifestArgs) -> Self {
215        Self {
216            app: a.app,
217            depot: a.depot,
218            manifest: a.manifest,
219            branch: a.branch,
220            output: pathbuf_to_string(a.output),
221        }
222    }
223}
224
225impl From<crate::cli::WorkshopArgs> for WorkshopParams {
226    fn from(a: crate::cli::WorkshopArgs) -> Self {
227        Self {
228            app: a.app,
229            item: a.item,
230            output: a.output.map(pathbuf_to_string),
231        }
232    }
233}
234
235impl From<crate::cli::LocalInfoArgs> for LocalInfoParams {
236    fn from(a: crate::cli::LocalInfoArgs) -> Self {
237        Self {
238            format: a.format.map(Into::into),
239            user: a.user,
240            users: a.users,
241        }
242    }
243}
244
245impl From<DownloadParams> for crate::cli::DownloadArgs {
246    fn from(p: DownloadParams) -> Self {
247        Self {
248            app: p.app,
249            depot: p.depot,
250            manifest: p.manifest,
251            filelist: p.filelist.map(std::path::PathBuf::from),
252            file_regex: p.file_regex,
253            output: p.output.map(std::path::PathBuf::from),
254            verify: p.verify,
255            os: p.os,
256            arch: p.arch,
257            language: p.language,
258            login_id: p.login_id,
259            all_platforms: p.all_platforms,
260            all_architectures: p.all_architectures,
261            all_languages: p.all_languages,
262            lancache: p.lancache,
263            max_downloads: p.max_downloads.map(|n| n as usize),
264            branch: p.branch,
265            branch_password: p.branch_password,
266            local_keys: p.local_keys,
267            non_atomic: p.non_atomic,
268            save_manifests: p.save_manifests,
269            bytes: p.bytes,
270        }
271    }
272}
273
274impl From<InfoParams> for crate::cli::InfoArgs {
275    fn from(p: InfoParams) -> Self {
276        Self {
277            app: p.app,
278            format: p.format.map(Into::into),
279            os: p.os,
280            show_all: p.show_all,
281        }
282    }
283}
284
285impl From<FilesParams> for crate::cli::FilesArgs {
286    fn from(p: FilesParams) -> Self {
287        Self {
288            app: p.app,
289            depot: p.depot,
290            manifest: p.manifest,
291            manifest_file: p.manifest_file.map(std::path::PathBuf::from),
292            depot_key: p.depot_key,
293            branch: p.branch,
294            branch_password: p.branch_password,
295            os: p.os,
296            format: p.format.map(Into::into),
297            raw: p.raw,
298            bytes: p.bytes,
299        }
300    }
301}
302
303impl From<ManifestsParams> for crate::cli::ManifestsArgs {
304    fn from(p: ManifestsParams) -> Self {
305        Self {
306            app: p.app,
307            branch: p.branch,
308            branch_password: p.branch_password,
309            format: p.format.map(Into::into),
310        }
311    }
312}
313
314impl From<DiffParams> for crate::cli::DiffArgs {
315    fn from(p: DiffParams) -> Self {
316        Self {
317            app: p.app,
318            depot: p.depot,
319            from: p.from,
320            to: p.to,
321            branch: p.branch,
322            format: p.format.map(Into::into),
323        }
324    }
325}
326
327impl From<PackagesParams> for crate::cli::PackagesArgs {
328    fn from(p: PackagesParams) -> Self {
329        Self {
330            packages: p.packages,
331            format: p.format.map(Into::into),
332        }
333    }
334}
335
336impl From<SaveManifestParams> for crate::cli::SaveManifestArgs {
337    fn from(p: SaveManifestParams) -> Self {
338        Self {
339            app: p.app,
340            depot: p.depot,
341            manifest: p.manifest,
342            branch: p.branch,
343            output: std::path::PathBuf::from(p.output),
344        }
345    }
346}
347
348impl From<WorkshopParams> for crate::cli::WorkshopArgs {
349    fn from(p: WorkshopParams) -> Self {
350        Self {
351            app: p.app,
352            item: p.item,
353            output: p.output.map(std::path::PathBuf::from),
354        }
355    }
356}
357
358impl From<LocalInfoParams> for crate::cli::LocalInfoArgs {
359    fn from(p: LocalInfoParams) -> Self {
360        Self {
361            format: p.format.map(Into::into),
362            user: p.user,
363            users: p.users,
364        }
365    }
366}
367
368#[cfg(test)]
369mod tests {
370    use super::*;
371    use rkyv::rancor;
372
373    #[test]
374    fn download_params_round_trip() {
375        let p = DownloadParams {
376            app: 730,
377            depot: Some(731),
378            manifest: Some(1234),
379            filelist: Some("files.txt".into()),
380            file_regex: Some(r"\.dll$".into()),
381            output: Some("out".into()),
382            verify: true,
383            os: None,
384            arch: None,
385            language: None,
386            login_id: None,
387            all_platforms: false,
388            all_architectures: false,
389            all_languages: false,
390            lancache: false,
391            max_downloads: Some(16),
392            branch: Some("public".into()),
393            branch_password: None,
394            local_keys: false,
395            non_atomic: false,
396            save_manifests: false,
397            bytes: false,
398        };
399        let bytes = rkyv::to_bytes::<rancor::Error>(&p).unwrap();
400        let back = rkyv::from_bytes::<DownloadParams, rancor::Error>(&bytes).unwrap();
401        assert_eq!(back.app, 730);
402        assert_eq!(back.depot, Some(731));
403        assert_eq!(back.file_regex.as_deref(), Some(r"\.dll$"));
404        assert_eq!(back.max_downloads, Some(16));
405    }
406
407    #[test]
408    fn packages_params_round_trip_with_vec() {
409        let p = PackagesParams {
410            packages: vec![1, 2, 3],
411            format: Some(OutputFormat::Json),
412        };
413        let bytes = rkyv::to_bytes::<rancor::Error>(&p).unwrap();
414        let back = rkyv::from_bytes::<PackagesParams, rancor::Error>(&bytes).unwrap();
415        assert_eq!(back.packages, vec![1, 2, 3]);
416        assert!(matches!(back.format, Some(OutputFormat::Json)));
417    }
418}