pathman/lib.rs
1use crate::platform::PathUpdater;
2use crate::platform::PlatformPathUpdater;
3use std::path::Path;
4
5mod error;
6mod platform;
7
8pub use error::PathmanError;
9pub use platform::UpdateType;
10
11/// Prepends the given path to the PATH environment variable
12///
13/// This function provides a cross-platform interface for prepending a given
14/// path to the user's PATH environment variable.
15///
16/// It is generally necessary for the end user to restart their shell or to
17/// source their shell configuration file for the changes to take effect.
18///
19/// # OS-specific behavior
20///
21/// This function behaves differently depending on the operating system,
22/// because the method of modifying the PATH environment variable varies
23/// across platforms.
24///
25/// # macOS and Linux
26///
27/// On macOS and Linux, PATH is modified by adding a command to the user's
28/// shell configuration file (e.g., `.bashrc`, `.zshrc`, etc.).
29///
30/// # Windows
31///
32/// On Windows, the user's PATH is modified by updating the registry.
33pub fn prepend_to_path<P: AsRef<Path>>(
34 path: P,
35 comment: Option<&str>,
36) -> Result<UpdateType, PathmanError> {
37 PlatformPathUpdater::prepend(path, comment)
38}
39
40/// Appends the given path to the PATH environment variable
41///
42/// This function provides a cross-platform interface for appending a given
43/// path to the user's PATH environment variable.
44///
45/// It is generally necessary for the end user to restart their shell or to
46/// source their shell configuration file for the changes to take effect.
47///
48/// # OS-specific behavior
49///
50/// This function behaves differently depending on the operating system,
51/// because the method of modifying the PATH environment variable varies
52/// across platforms.
53///
54/// # macOS and Linux
55///
56/// On macOS and Linux, PATH is modified by adding a command to the user's
57/// shell configuration file (e.g., `.bashrc`, `.zshrc`, etc.).
58///
59/// # Windows
60///
61/// On Windows, the user's PATH is modified by updating the registry.
62pub fn append_to_path<P: AsRef<Path>>(
63 path: P,
64 comment: Option<&str>,
65) -> Result<UpdateType, PathmanError> {
66 PlatformPathUpdater::append(path, comment)
67}