winget_types/installer/switches/
mod.rs

1mod custom;
2mod install_location;
3mod interactive;
4mod log;
5mod repair;
6mod silent;
7mod silent_with_progress;
8mod switch;
9mod upgrade;
10
11use bon::Builder;
12
13pub use super::switches::{
14    custom::CustomSwitch, install_location::InstallLocationSwitch, interactive::InteractiveSwitch,
15    log::LogSwitch, repair::RepairSwitch, silent::SilentSwitch,
16    silent_with_progress::SilentWithProgressSwitch, upgrade::UpgradeSwitch,
17};
18
19#[derive(Builder, Clone, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
20#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
21#[cfg_attr(feature = "serde", serde(rename_all = "PascalCase"))]
22pub struct InstallerSwitches {
23    /// Switches passed to the installer to provide a silent install experience.
24    ///
25    /// These would be used when the command `winget install <package> --silent` is executed.
26    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
27    pub(crate) silent: Option<SilentSwitch>,
28
29    /// Switches passed to the installer to provide a silent with progress install experience.
30    ///
31    /// This is intended to allow a progress indication to the user, and the indication may come
32    /// from an installer UI dialogue, but it must not require user interaction to complete. The
33    /// Windows Package Manager currently defaults to this install experience.
34    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
35    pub(crate) silent_with_progress: Option<SilentWithProgressSwitch>,
36
37    /// Switches passed to the installer to provide an interactive install experience.
38    ///
39    /// This is intended to allow a user to interact with the installer. These would be used when
40    /// the command `winget install <package> --interactive` is executed.
41    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
42    pub(crate) interactive: Option<InteractiveSwitch>,
43
44    /// The path to install the package if the installer supports installing the package in a user
45    /// configurable location.
46    ///
47    /// The `<INSTALLPATH>` token can be included in the switch value so the Windows Package Manager
48    /// will replace the token with user provided path.
49    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
50    pub(crate) install_location: Option<InstallLocationSwitch>,
51
52    /// The path logs will be directed to if the installer supports specifying the log path in a
53    /// user configurable location.
54    ///
55    /// The `<LOGPATH>` token can be included in the switch value so the Windows Package Manager
56    /// will replace the token with user provided path.
57    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
58    pub(crate) log: Option<LogSwitch>,
59
60    /// The switches to be passed to the installer during an upgrade. This will happen only if the
61    /// upgrade behavior is "install".
62    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
63    pub(crate) upgrade: Option<UpgradeSwitch>,
64
65    /// Any switches the Windows Package Manager will pass to the installer in addition to `Silent`,
66    /// `SilentWithProgress`, and `Interactive`.
67    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
68    pub(crate) custom: Option<CustomSwitch>,
69
70    /// The switches to be passed during the repair of an existing installation.
71    ///
72    /// This will be passed to the installer, `ModifyPath` ARP command, or Uninstaller ARP command
73    /// depending on the `RepairBehavior` specified in the manifest.
74    #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
75    pub(crate) repair: Option<RepairSwitch>,
76}
77
78impl InstallerSwitches {
79    /// Returns the silent switch, if any.
80    #[must_use]
81    #[inline]
82    pub const fn silent(&self) -> Option<&SilentSwitch> {
83        self.silent.as_ref()
84    }
85
86    /// Returns the silent with progress switch, if any.
87    #[must_use]
88    #[inline]
89    pub const fn silent_with_progress(&self) -> Option<&SilentWithProgressSwitch> {
90        self.silent_with_progress.as_ref()
91    }
92
93    /// Returns the interactive switch, if any.
94    #[must_use]
95    #[inline]
96    pub const fn interactive(&self) -> Option<&InteractiveSwitch> {
97        self.interactive.as_ref()
98    }
99
100    /// Returns the log switch, if any.
101    #[must_use]
102    #[inline]
103    pub const fn log(&self) -> Option<&LogSwitch> {
104        self.log.as_ref()
105    }
106
107    /// Returns the upgrade switch, if any.
108    #[must_use]
109    #[inline]
110    pub const fn upgrade(&self) -> Option<&UpgradeSwitch> {
111        self.upgrade.as_ref()
112    }
113
114    /// Returns the custom switch, if any.
115    #[must_use]
116    #[inline]
117    pub const fn custom(&self) -> Option<&CustomSwitch> {
118        self.custom.as_ref()
119    }
120
121    /// Returns the repair switch, if any.
122    #[must_use]
123    #[inline]
124    pub const fn repair(&self) -> Option<&RepairSwitch> {
125        self.repair.as_ref()
126    }
127
128    /// Returns `true` if no switches are present.
129    ///
130    /// # Examples
131    ///
132    /// ```
133    /// use winget_types::installer::{switches, InstallerSwitches};
134    ///
135    /// let switches = InstallerSwitches::builder().build();
136    /// assert!(switches.is_empty());
137    ///
138    /// let switches = InstallerSwitches::builder().maybe_silent("--silent".parse().ok()).build();
139    /// assert!(!switches.is_empty());
140    /// ```
141    #[must_use]
142    pub const fn is_empty(&self) -> bool {
143        self.silent.is_none()
144            && self.silent_with_progress.is_none()
145            && self.interactive.is_none()
146            && self.install_location.is_none()
147            && self.log.is_none()
148            && self.upgrade.is_none()
149            && self.custom.is_none()
150            && self.repair.is_none()
151    }
152}
153
154impl Default for InstallerSwitches {
155    fn default() -> Self {
156        Self::builder().build()
157    }
158}