cargo_packager_utils/
lib.rs1use std::fmt::Display;
10
11pub mod current_exe;
12
13#[derive(Clone, Copy, Debug, Eq, PartialEq)]
17#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
18#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))]
19#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
20#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
21#[cfg_attr(feature = "clap", value(rename_all = "lowercase"))]
22#[non_exhaustive]
23pub enum PackageFormat {
24 #[cfg(feature = "cli")]
28 All,
29 #[cfg(feature = "cli")]
33 Default,
34 App,
36 Dmg,
38 Wix,
40 Nsis,
42 Deb,
44 AppImage,
46 Pacman,
48}
49
50impl Display for PackageFormat {
51 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52 write!(f, "{}", self.short_name())
53 }
54}
55
56impl PackageFormat {
57 pub fn from_short_name(name: &str) -> Option<PackageFormat> {
60 match name {
62 "app" => Some(PackageFormat::App),
63 "dmg" => Some(PackageFormat::Dmg),
64 "wix" => Some(PackageFormat::Wix),
65 "nsis" => Some(PackageFormat::Nsis),
66 "deb" => Some(PackageFormat::Deb),
67 "appimage" => Some(PackageFormat::AppImage),
68 _ => None,
69 }
70 }
71
72 pub fn short_name(&self) -> &'static str {
74 match *self {
75 #[cfg(feature = "cli")]
76 PackageFormat::All => "all",
77 #[cfg(feature = "cli")]
78 PackageFormat::Default => "default",
79 PackageFormat::App => "app",
80 PackageFormat::Dmg => "dmg",
81 PackageFormat::Wix => "wix",
82 PackageFormat::Nsis => "nsis",
83 PackageFormat::Deb => "deb",
84 PackageFormat::AppImage => "appimage",
85 PackageFormat::Pacman => "pacman",
86 }
87 }
88
89 pub fn platform_all() -> &'static [PackageFormat] {
95 &[
96 #[cfg(target_os = "macos")]
97 PackageFormat::App,
98 #[cfg(target_os = "macos")]
99 PackageFormat::Dmg,
100 #[cfg(target_os = "windows")]
101 PackageFormat::Wix,
102 #[cfg(target_os = "windows")]
103 PackageFormat::Nsis,
104 #[cfg(any(
105 target_os = "linux",
106 target_os = "dragonfly",
107 target_os = "freebsd",
108 target_os = "netbsd",
109 target_os = "openbsd"
110 ))]
111 PackageFormat::Deb,
112 #[cfg(any(
113 target_os = "linux",
114 target_os = "dragonfly",
115 target_os = "freebsd",
116 target_os = "netbsd",
117 target_os = "openbsd"
118 ))]
119 PackageFormat::AppImage,
120 #[cfg(any(
121 target_os = "linux",
122 target_os = "dragonfly",
123 target_os = "freebsd",
124 target_os = "netbsd",
125 target_os = "openbsd"
126 ))]
127 PackageFormat::Pacman,
128 ]
129 }
130
131 pub fn platform_default() -> &'static [PackageFormat] {
137 &[
138 #[cfg(target_os = "macos")]
139 PackageFormat::App,
140 #[cfg(target_os = "macos")]
141 PackageFormat::Dmg,
142 #[cfg(target_os = "windows")]
143 PackageFormat::Nsis,
144 #[cfg(any(
145 target_os = "linux",
146 target_os = "dragonfly",
147 target_os = "freebsd",
148 target_os = "netbsd",
149 target_os = "openbsd"
150 ))]
151 PackageFormat::Deb,
152 #[cfg(any(
153 target_os = "linux",
154 target_os = "dragonfly",
155 target_os = "freebsd",
156 target_os = "netbsd",
157 target_os = "openbsd"
158 ))]
159 PackageFormat::AppImage,
160 #[cfg(any(
161 target_os = "linux",
162 target_os = "dragonfly",
163 target_os = "freebsd",
164 target_os = "netbsd",
165 target_os = "openbsd"
166 ))]
167 PackageFormat::Pacman,
168 ]
169 }
170
171 pub fn priority(&self) -> u32 {
178 match self {
179 #[cfg(feature = "cli")]
180 PackageFormat::All => 0,
181 #[cfg(feature = "cli")]
182 PackageFormat::Default => 0,
183 PackageFormat::App => 0,
184 PackageFormat::Wix => 0,
185 PackageFormat::Nsis => 0,
186 PackageFormat::Deb => 0,
187 PackageFormat::AppImage => 0,
188 PackageFormat::Pacman => 0,
189 PackageFormat::Dmg => 1,
190 }
191 }
192}