takecrate/inst/config.rs
1use std::path::PathBuf;
2
3use crate::{error::InstallerError, os::AccessScope, path::AppPathPrefix};
4
5/// Parameters that control how the binary is installed.
6#[derive(Debug, Clone, Default)]
7#[non_exhaustive]
8pub struct InstallConfig {
9 /// Access scope.
10 pub access_scope: AccessScope,
11 /// Where the files will be installed.
12 pub destination: AppPathPrefix,
13 /// Where the files are coming from.
14 pub source_dir: PathBuf,
15 /// Whether to modify the search path (PATH).
16 ///
17 /// On Windows, this will modify the environment variable and App Paths
18 /// in the registry.
19 ///
20 /// On Unix with user scope, this will modify the user's shell profile
21 /// config. The SHELL variable and the existence of
22 /// the `.bash_profile`, `.zprofile`, or `.profile` will be used to select
23 /// the appropriate file. If the file already contains the path, it will
24 /// not be modified.
25 /// For system scope, it's not supported.
26 pub modify_os_search_path: bool,
27}
28
29impl InstallConfig {
30 /// Create a new config suitable for a User install.
31 pub fn new_user() -> Result<Self, InstallerError> {
32 Ok(Self {
33 access_scope: AccessScope::User,
34 destination: AppPathPrefix::User,
35 source_dir: crate::os::current_exe_dir()?,
36 modify_os_search_path: true,
37 })
38 }
39
40 /// Create a new config suitable for a System install.
41 pub fn new_system() -> Result<Self, InstallerError> {
42 Ok(Self {
43 access_scope: AccessScope::System,
44 destination: AppPathPrefix::System,
45 source_dir: crate::os::current_exe_dir()?,
46 modify_os_search_path: true,
47 })
48 }
49}