cargo_packager/config/
builder.rs1use std::path::PathBuf;
2
3use crate::{Config, PackageFormat};
4
5use super::{
6 AppImageConfig, Binary, DebianConfig, FileAssociation, HookCommand, LogLevel, MacOsConfig,
7 NsisConfig, PacmanConfig, Resource, WindowsConfig, WixConfig,
8};
9
10#[derive(Default)]
12pub struct ConfigBuilder(Config);
13
14impl ConfigBuilder {
15 pub fn new() -> Self {
17 Self::default()
18 }
19
20 pub fn config(&self) -> &Config {
22 &self.0
23 }
24
25 pub fn product_name<S: Into<String>>(mut self, product_name: S) -> Self {
27 self.0.product_name = product_name.into();
28 self
29 }
30
31 pub fn version<S: Into<String>>(mut self, version: S) -> Self {
33 self.0.version = version.into();
34 self
35 }
36
37 pub fn binaries<I: IntoIterator<Item = Binary>>(mut self, binaries: I) -> Self {
39 self.0.binaries = binaries.into_iter().collect();
40 self
41 }
42
43 pub fn identifier<S: Into<String>>(mut self, identifier: S) -> Self {
45 self.0.identifier.replace(identifier.into());
46 self
47 }
48
49 pub fn before_packaging_command(mut self, command: HookCommand) -> Self {
51 self.0.before_packaging_command.replace(command);
52 self
53 }
54
55 pub fn before_each_package_command(mut self, command: HookCommand) -> Self {
57 self.0.before_each_package_command.replace(command);
58 self
59 }
60
61 pub fn log_level(mut self, level: LogLevel) -> Self {
63 self.0.log_level.replace(level);
64 self
65 }
66
67 pub fn formats<I: IntoIterator<Item = PackageFormat>>(mut self, formats: I) -> Self {
69 self.0.formats = Some(formats.into_iter().collect());
70 self
71 }
72
73 pub fn out_dir<P: Into<PathBuf>>(mut self, path: P) -> Self {
75 self.0.out_dir = path.into();
76 self
77 }
78
79 pub fn target_triple<S: Into<String>>(mut self, target_triple: S) -> Self {
81 self.0.target_triple.replace(target_triple.into());
82 self
83 }
84
85 pub fn description<S: Into<String>>(mut self, description: S) -> Self {
87 self.0.description.replace(description.into());
88 self
89 }
90
91 pub fn long_description<S: Into<String>>(mut self, long_description: S) -> Self {
93 self.0.long_description.replace(long_description.into());
94 self
95 }
96
97 pub fn homepage<S: Into<String>>(mut self, homepage: S) -> Self {
99 self.0.homepage.replace(homepage.into());
100 self
101 }
102
103 pub fn authors<I, S>(mut self, authors: I) -> Self
105 where
106 I: IntoIterator<Item = S>,
107 S: Into<String>,
108 {
109 self.0
110 .authors
111 .replace(authors.into_iter().map(Into::into).collect());
112 self
113 }
114
115 pub fn publisher<S: Into<String>>(mut self, publisher: S) -> Self {
117 self.0.publisher.replace(publisher.into());
118 self
119 }
120
121 pub fn license_file<P: Into<PathBuf>>(mut self, license_file: P) -> Self {
123 self.0.license_file.replace(license_file.into());
124 self
125 }
126
127 pub fn copyright<S: Into<String>>(mut self, copyright: S) -> Self {
129 self.0.copyright.replace(copyright.into());
130 self
131 }
132
133 pub fn icons<I, S>(mut self, icons: I) -> Self
135 where
136 I: IntoIterator<Item = S>,
137 S: Into<String>,
138 {
139 self.0
140 .icons
141 .replace(icons.into_iter().map(Into::into).collect());
142 self
143 }
144
145 pub fn file_associations<I: IntoIterator<Item = FileAssociation>>(
147 mut self,
148 file_associations: I,
149 ) -> Self {
150 self.0
151 .file_associations
152 .replace(file_associations.into_iter().collect());
153 self
154 }
155
156 pub fn resources<I: IntoIterator<Item = Resource>>(mut self, resources: I) -> Self {
158 self.0.resources.replace(resources.into_iter().collect());
159 self
160 }
161
162 pub fn external_binaries<I, P>(mut self, external_binaries: I) -> Self
164 where
165 I: IntoIterator<Item = P>,
166 P: Into<PathBuf>,
167 {
168 self.0
169 .external_binaries
170 .replace(external_binaries.into_iter().map(Into::into).collect());
171 self
172 }
173
174 pub fn windows(mut self, windows: WindowsConfig) -> Self {
176 self.0.windows.replace(windows);
177 self
178 }
179
180 pub fn macos(mut self, macos: MacOsConfig) -> Self {
182 self.0.macos.replace(macos);
183 self
184 }
185
186 pub fn wix(mut self, wix: WixConfig) -> Self {
188 self.0.wix.replace(wix);
189 self
190 }
191
192 pub fn nsis(mut self, nsis: NsisConfig) -> Self {
194 self.0.nsis.replace(nsis);
195 self
196 }
197
198 pub fn deb(mut self, deb: DebianConfig) -> Self {
200 self.0.deb.replace(deb);
201 self
202 }
203
204 pub fn appimage(mut self, appimage: AppImageConfig) -> Self {
206 self.0.appimage.replace(appimage);
207 self
208 }
209
210 pub fn pacman(mut self, pacman: PacmanConfig) -> Self {
212 self.0.pacman.replace(pacman);
213 self
214 }
215}