Debian Codegraph @

src/env.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/;
2
3 const COLORTERMrust-analyzer cargo git-delta 0.19.2 env/COLORTERM.: &str = "COLORTERM";
4 const BAT_THEMErust-analyzer cargo git-delta 0.19.2 env/BAT_THEME.: &str = "BAT_THEME";
5 const GIT_CONFIG_PARAMETERSrust-analyzer cargo git-delta 0.19.2 env/GIT_CONFIG_PARAMETERS.: &str = "GIT_CONFIG_PARAMETERS";
6 const GIT_PREFIXrust-analyzer cargo git-delta 0.19.2 env/GIT_PREFIX.: &str = "GIT_PREFIX";
7 const DELTA_FEATURESrust-analyzer cargo git-delta 0.19.2 env/DELTA_FEATURES.: &str = "DELTA_FEATURES";
8 const DELTA_NAVIGATErust-analyzer cargo git-delta 0.19.2 env/DELTA_NAVIGATE.: &str = "DELTA_NAVIGATE";
9 const DELTA_EXPERIMENTAL_MAX_LINE_DISTANCE_FOR_NAIVELY_PAIRED_LINESrust-analyzer cargo git-delta 0.19.2 env/DELTA_EXPERIMENTAL_MAX_LINE_DISTANCE_FOR_NAIVELY_PAIRED_LINES.: &str =
10 "DELTA_EXPERIMENTAL_MAX_LINE_DISTANCE_FOR_NAIVELY_PAIRED_LINES";
11 const DELTA_PAGERrust-analyzer cargo git-delta 0.19.2 env/DELTA_PAGER.: &str = "DELTA_PAGER";
12
13 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
14 pub struct DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv# {
15 pub bat_themerust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#bat_theme.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
16 pub colortermrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#colorterm.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
17 pub current_dirrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#current_dir.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#>,
18 pub experimental_max_line_distance_for_naively_paired_linesrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#experimental_max_line_distance_for_naively_paired_lines.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
19 pub featuresrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#features.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
20 pub git_config_parametersrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#git_config_parameters.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
21 pub git_prefixrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#git_prefix.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
22 pub hostnamerust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#hostname.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
23 pub navigaterust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#navigate.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
24 pub pagersrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#pagers.: (Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>),
25 }
26
27 impl DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv# {
28 /// Create a structure with current environment variable
29 pub fn initrust-analyzer cargo git-delta 0.19.2 env/impl#[DeltaEnv]init().() -> Selfrust-analyzer cargo git-delta 0.19.2 env/impl#[DeltaEnv] {
30 let bat_theme = envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().(BAT_THEMErust-analyzer cargo git-delta 0.19.2 env/BAT_THEME.).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().();
31 let colorterm = envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().(COLORTERMrust-analyzer cargo git-delta 0.19.2 env/COLORTERM.).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().();
32 let experimental_max_line_distance_for_naively_paired_lines =
33 envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().(DELTA_EXPERIMENTAL_MAX_LINE_DISTANCE_FOR_NAIVELY_PAIRED_LINESrust-analyzer cargo git-delta 0.19.2 env/DELTA_EXPERIMENTAL_MAX_LINE_DISTANCE_FOR_NAIVELY_PAIRED_LINES.).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().();
34 let features = envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().(DELTA_FEATURESrust-analyzer cargo git-delta 0.19.2 env/DELTA_FEATURES.).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().();
35 let git_config_parameters = envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().(GIT_CONFIG_PARAMETERSrust-analyzer cargo git-delta 0.19.2 env/GIT_CONFIG_PARAMETERS.).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().();
36 let git_prefix = envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().(GIT_PREFIXrust-analyzer cargo git-delta 0.19.2 env/GIT_PREFIX.).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().();
37 let hostname = hostnamerust-analyzer cargo git-delta 0.19.2 env/hostname().();
38 let navigate = envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().(DELTA_NAVIGATErust-analyzer cargo git-delta 0.19.2 env/DELTA_NAVIGATE.).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().();
39
40 let current_dir = envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::current_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/current_dir().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().();
41 let pagers = (
42 envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().(DELTA_PAGERrust-analyzer cargo git-delta 0.19.2 env/DELTA_PAGER.).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().(),
43 // We're using `bat::config::get_pager_executable` here instead of just returning
44 // the pager from the environment variables, because we want to make sure
45 // that the pager is a valid pager from env and handle the case of
46 // the PAGER being set to something invalid like "most" and "more".
47 batrust-analyzer cargo bat 0.26.1 crate/::configrust-analyzer cargo bat 0.26.1 config/::get_pager_executablerust-analyzer cargo bat 0.26.1 config/get_pager_executable().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
48 );
49
50 Selfrust-analyzer cargo git-delta 0.19.2 env/impl#[DeltaEnv] {
51 bat_themerust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#bat_theme.,
52 colortermrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#colorterm.,
53 current_dirrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#current_dir.,
54 experimental_max_line_distance_for_naively_paired_linesrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#experimental_max_line_distance_for_naively_paired_lines.,
55 featuresrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#features.,
56 git_config_parametersrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#git_config_parameters.,
57 git_prefixrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#git_prefix.,
58 hostnamerust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#hostname.,
59 navigaterust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#navigate.,
60 pagersrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#pagers.,
61 }
62 }
63 }
64
65 fn hostnamerust-analyzer cargo git-delta 0.19.2 env/hostname().() -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
66 grep_clirust-analyzer cargo grep-cli 0.1.12 crate/::hostnamerust-analyzer cargo grep-cli 0.1.12 hostname/hostname().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()..to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_str().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|s| s.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
67 }
68
69 #[cfg(test)]
70 pub mod testsrust-analyzer cargo git-delta 0.19.2 env/tests/ {
71 use superrust-analyzer cargo git-delta 0.19.2 env/::DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#;
72 use lazy_staticrust-analyzer cargo lazy_static 1.4.0 crate/::lazy_staticrust-analyzer cargo lazy_static 1.4.0 lazy_static!;
73 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/;
74 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::{Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#, Mutexrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/Mutex#};
75
76 lazy_staticrust-analyzer cargo lazy_static 1.4.0 lazy_static!! {
77 static ref ENV_ACCESSrust-analyzer cargo git-delta 0.19.2 env/tests/ENV_ACCESS#: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<Mutexrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/Mutex#<()>> = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(Mutexrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/Mutex#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]new().(()));
78 }
79
80 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
81 fn test_env_parsingrust-analyzer cargo git-delta 0.19.2 env/tests/test_env_parsing().() {
82 let _guard = ENV_ACCESSrust-analyzer cargo git-delta 0.19.2 env/tests/ENV_ACCESS..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
83 let feature = "Awesome Feature";
84 envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("DELTA_FEATURES", feature);
85 let env = DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#::initrust-analyzer cargo git-delta 0.19.2 env/impl#[DeltaEnv]init().();
86 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(env.featuresrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#features., Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(feature.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()));
87 // otherwise `current_dir` is not used in the test cfg:
88 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(env.current_dirrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#current_dir., envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::current_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/current_dir().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().());
89 }
90
91 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
92 fn test_env_parsing_with_pager_set_to_batrust-analyzer cargo git-delta 0.19.2 env/tests/test_env_parsing_with_pager_set_to_bat().() {
93 let _guard = ENV_ACCESSrust-analyzer cargo git-delta 0.19.2 env/tests/ENV_ACCESS..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
94 envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("PAGER", "bat");
95 let env = DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#::initrust-analyzer cargo git-delta 0.19.2 env/impl#[DeltaEnv]init().();
96 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
97 env.pagersrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#pagers..1,
98 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("bat".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()),
99 "Expected env.pagers.1 == Some(bat) but was {:?}",
100 env.pagersrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#pagers..1
101 );
102 }
103
104 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
105 fn test_env_parsing_with_pager_set_to_morerust-analyzer cargo git-delta 0.19.2 env/tests/test_env_parsing_with_pager_set_to_more().() {
106 let _guard = ENV_ACCESSrust-analyzer cargo git-delta 0.19.2 env/tests/ENV_ACCESS..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
107 envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("PAGER", "more");
108 let env = DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#::initrust-analyzer cargo git-delta 0.19.2 env/impl#[DeltaEnv]init().();
109 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(env.pagersrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#pagers..1, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("less".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()));
110 }
111
112 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
113 fn test_env_parsing_with_pager_set_to_mostrust-analyzer cargo git-delta 0.19.2 env/tests/test_env_parsing_with_pager_set_to_most().() {
114 let _guard = ENV_ACCESSrust-analyzer cargo git-delta 0.19.2 env/tests/ENV_ACCESS..lockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/poison/mutex/impl#[`Mutex<T>`]lock().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
115 envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::set_varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/set_var().("PAGER", "most");
116 let env = DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#::initrust-analyzer cargo git-delta 0.19.2 env/impl#[DeltaEnv]init().();
117 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(env.pagersrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#pagers..1, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("less".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()));
118 }
119 }