parent
c6a7217ebd
commit
8f786cfd36
7 changed files with 33 additions and 1 deletions
|
@ -68,7 +68,9 @@ where
|
||||||
line.to_string()
|
line.to_string()
|
||||||
} else if let Some(cur_sections) = current_sections.clone() {
|
} else if let Some(cur_sections) = current_sections.clone() {
|
||||||
let trimmed_line = line.trim_start_matches(['#', ' ']);
|
let trimmed_line = line.trim_start_matches(['#', ' ']);
|
||||||
if should_enable_variable(&choose_sections, &cur_sections) {
|
if !is_variables(trimmed_line) {
|
||||||
|
line.to_string()
|
||||||
|
} else if should_enable_variable(&choose_sections, &cur_sections) {
|
||||||
String::from(trimmed_line)
|
String::from(trimmed_line)
|
||||||
} else if should_disable_variable(&choose_sections, &cur_sections) {
|
} else if should_disable_variable(&choose_sections, &cur_sections) {
|
||||||
format!("# {}", trimmed_line)
|
format!("# {}", trimmed_line)
|
||||||
|
@ -87,6 +89,15 @@ where
|
||||||
writer.flush().map_err(|_| Error::WriteData)
|
writer.flush().map_err(|_| Error::WriteData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_variables(trimmed_line: &str) -> bool {
|
||||||
|
trimmed_line
|
||||||
|
.chars()
|
||||||
|
.filter(|ch| (*ch != '_' && ch.is_ascii_punctuation()) || ch.is_whitespace())
|
||||||
|
.enumerate()
|
||||||
|
.find(|(_, ch)| *ch == '=')
|
||||||
|
.map_or(false, |(i, _)| i == 0)
|
||||||
|
}
|
||||||
|
|
||||||
fn is_section_end(line: &str) -> bool {
|
fn is_section_end(line: &str) -> bool {
|
||||||
line.trim().is_empty()
|
line.trim().is_empty()
|
||||||
}
|
}
|
||||||
|
@ -274,5 +285,20 @@ mod tests {
|
||||||
&[Section::with_namespace("debug", "off")]
|
&[Section::with_namespace("debug", "off")]
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_check_line_on_variable() {
|
||||||
|
let test_cases = [
|
||||||
|
("VAR=10", true),
|
||||||
|
("THIS_IS_MY_VAR='hello world'", true),
|
||||||
|
("hello world", false),
|
||||||
|
("staging/production", false),
|
||||||
|
("staging/production=value", false),
|
||||||
|
];
|
||||||
|
|
||||||
|
for (input, expected) in test_cases {
|
||||||
|
assert_eq!(is_variables(input), expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ VITE_STRIPE_PK=
|
||||||
VITE_SENTRY_ENABLED=
|
VITE_SENTRY_ENABLED=
|
||||||
VITE_SENTRY_DSN=
|
VITE_SENTRY_DSN=
|
||||||
### local,staging
|
### local,staging
|
||||||
|
# staging/production
|
||||||
VITE_SENTRY_ENV=staging
|
VITE_SENTRY_ENV=staging
|
||||||
### prod
|
### prod
|
||||||
VITE_SENTRY_ENV=production
|
VITE_SENTRY_ENV=production
|
||||||
|
|
|
@ -2,6 +2,7 @@ VITE_STRIPE_PK=
|
||||||
VITE_SENTRY_ENABLED=
|
VITE_SENTRY_ENABLED=
|
||||||
VITE_SENTRY_DSN=
|
VITE_SENTRY_DSN=
|
||||||
### local,staging
|
### local,staging
|
||||||
|
# staging/production
|
||||||
# VITE_SENTRY_ENV=staging
|
# VITE_SENTRY_ENV=staging
|
||||||
### prod
|
### prod
|
||||||
# VITE_SENTRY_ENV=production
|
# VITE_SENTRY_ENV=production
|
||||||
|
|
|
@ -2,6 +2,7 @@ VITE_STRIPE_PK=
|
||||||
VITE_SENTRY_ENABLED=
|
VITE_SENTRY_ENABLED=
|
||||||
VITE_SENTRY_DSN=
|
VITE_SENTRY_DSN=
|
||||||
### local,staging
|
### local,staging
|
||||||
|
# staging/production
|
||||||
VITE_SENTRY_ENV=staging
|
VITE_SENTRY_ENV=staging
|
||||||
### prod
|
### prod
|
||||||
# VITE_SENTRY_ENV=production
|
# VITE_SENTRY_ENV=production
|
||||||
|
|
|
@ -2,6 +2,7 @@ VITE_STRIPE_PK=
|
||||||
VITE_SENTRY_ENABLED=
|
VITE_SENTRY_ENABLED=
|
||||||
VITE_SENTRY_DSN=
|
VITE_SENTRY_DSN=
|
||||||
### local,staging
|
### local,staging
|
||||||
|
# staging/production
|
||||||
VITE_SENTRY_ENV=staging
|
VITE_SENTRY_ENV=staging
|
||||||
### prod
|
### prod
|
||||||
# VITE_SENTRY_ENV=production
|
# VITE_SENTRY_ENV=production
|
||||||
|
|
|
@ -2,6 +2,7 @@ VITE_STRIPE_PK=
|
||||||
VITE_SENTRY_ENABLED=
|
VITE_SENTRY_ENABLED=
|
||||||
VITE_SENTRY_DSN=
|
VITE_SENTRY_DSN=
|
||||||
### local,staging
|
### local,staging
|
||||||
|
# staging/production
|
||||||
VITE_SENTRY_ENV=staging
|
VITE_SENTRY_ENV=staging
|
||||||
### prod
|
### prod
|
||||||
# VITE_SENTRY_ENV=production
|
# VITE_SENTRY_ENV=production
|
||||||
|
|
|
@ -2,6 +2,7 @@ VITE_STRIPE_PK=
|
||||||
VITE_SENTRY_ENABLED=
|
VITE_SENTRY_ENABLED=
|
||||||
VITE_SENTRY_DSN=
|
VITE_SENTRY_DSN=
|
||||||
### local,staging
|
### local,staging
|
||||||
|
# staging/production
|
||||||
VITE_SENTRY_ENV=staging
|
VITE_SENTRY_ENV=staging
|
||||||
### prod
|
### prod
|
||||||
# VITE_SENTRY_ENV=production
|
# VITE_SENTRY_ENV=production
|
||||||
|
|
Loading…
Reference in a new issue