| |
| |
| |
| |
| |
|
|
| #ifndef MAMBA_UTIL_ENVIRONMENT_HPP |
| #define MAMBA_UTIL_ENVIRONMENT_HPP |
|
|
| #include <optional> |
| #include <string> |
| #include <string_view> |
| #include <unordered_map> |
| #include <vector> |
|
|
| #include "mamba/fs/filesystem.hpp" |
| #include "mamba/util/build.hpp" |
|
|
| namespace mamba::util |
| { |
| |
| |
| |
| [[nodiscard]] auto get_env(const std::string& key) -> std::optional<std::string>; |
|
|
| |
| |
| |
| void set_env(const std::string& key, const std::string& value); |
|
|
| |
| |
| |
| void unset_env(const std::string& key); |
|
|
| using environment_map = std::unordered_map<std::string, std::string>; |
|
|
| |
| |
| |
| |
| |
| |
| [[nodiscard]] auto get_env_map() -> environment_map; |
|
|
| |
| |
| |
| |
| |
| void update_env_map(const environment_map& env); |
|
|
| |
| |
| |
| |
| |
| void set_env_map(const environment_map& env); |
|
|
| |
| |
| |
| [[nodiscard]] auto user_home_dir() -> std::string; |
|
|
| |
| |
| |
| |
| |
| |
| |
| [[nodiscard]] auto user_config_dir() -> std::string; |
|
|
| |
| |
| |
| |
| |
| |
| |
| [[nodiscard]] auto user_data_dir() -> std::string; |
|
|
| |
| |
| |
| |
| |
| |
| |
| [[nodiscard]] auto user_cache_dir() -> std::string; |
|
|
| |
| |
| |
| [[nodiscard]] constexpr auto pathsep() -> char; |
|
|
| |
| |
| |
| [[nodiscard]] auto get_path_dirs(const fs::u8path& prefix) -> std::vector<fs::u8path>; |
|
|
| |
| |
| |
| [[nodiscard]] auto which(std::string_view exe) -> fs::u8path; |
|
|
| |
| |
| |
| template <typename Iter> |
| [[nodiscard]] auto which_in(std::string_view exe, Iter search_path_first, Iter search_path_last) |
| -> fs::u8path; |
|
|
| |
| |
| |
| |
| |
| template <typename Range> |
| [[nodiscard]] auto which_in(std::string_view exe, const Range& search_paths) -> fs::u8path; |
|
|
| |
| |
| |
|
|
| constexpr auto pathsep() -> char |
| { |
| if (on_win) |
| { |
| return ';'; |
| } |
| else |
| { |
| return ':'; |
| } |
| } |
|
|
| namespace detail |
| { |
| [[nodiscard]] auto which_in_one(const fs::u8path& exe, const fs::u8path& dir) -> fs::u8path; |
|
|
| [[nodiscard]] auto which_in_split(const fs::u8path& exe, std::string_view paths) |
| -> fs::u8path; |
| } |
|
|
| template <typename Iter> |
| auto which_in(std::string_view exe, Iter first, Iter last) -> fs::u8path |
| { |
| for (; first != last; ++first) |
| { |
| if (auto p = detail::which_in_one(exe, *first); !p.empty()) |
| { |
| return p; |
| } |
| } |
| return ""; |
| } |
|
|
| template <typename Range> |
| auto which_in(std::string_view exe, const Range& search_paths) -> fs::u8path |
| { |
| if constexpr (std::is_same_v<Range, fs::u8path>) |
| { |
| return detail::which_in_one(exe, search_paths); |
| } |
| else if constexpr (std::is_convertible_v<Range, std::string_view>) |
| { |
| return detail::which_in_split(exe, search_paths); |
| } |
| else |
| { |
| return which_in(exe, search_paths.cbegin(), search_paths.cend()); |
| } |
| } |
| } |
| #endif |
|
|