set_local_db/set_dot_env diffs can contain secrets (connection strings), so printing them unconditionally on every up/down leaked credentials to stdout. Default output is now a line-count summary; pass -v/--verbose to see the actual before/after lines.
63 lines
1.4 KiB
Rust
63 lines
1.4 KiB
Rust
use anyhow::{bail, Result};
|
|
use clap::Parser;
|
|
|
|
#[derive(Parser, Default, Debug)]
|
|
#[clap(
|
|
author = "Mathias Rothenhäusler",
|
|
version,
|
|
about = "Start RCC local test environment."
|
|
)]
|
|
pub struct Arguments {
|
|
#[arg(help = "Which project folder to use, defined in your env file. E.g. xxx_DIR.")]
|
|
pub project: String,
|
|
|
|
#[arg(help = "Possible values are 'up' and 'down'")]
|
|
pub action: String,
|
|
|
|
#[arg(
|
|
short,
|
|
long,
|
|
help = "Show which lines were changed (values may include secrets)"
|
|
)]
|
|
pub verbose: bool,
|
|
}
|
|
|
|
impl Arguments {
|
|
pub fn validate(&self) -> Result<()> {
|
|
if self.action == "up" || self.action == "down" {
|
|
return Ok(());
|
|
}
|
|
|
|
bail!("Action values are up or down.")
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
fn args_with_action(action: &str) -> Arguments {
|
|
Arguments {
|
|
project: "test".to_string(),
|
|
action: action.to_string(),
|
|
verbose: false,
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn validate_accepts_up() {
|
|
assert!(args_with_action("up").validate().is_ok());
|
|
}
|
|
|
|
#[test]
|
|
fn validate_accepts_down() {
|
|
assert!(args_with_action("down").validate().is_ok());
|
|
}
|
|
|
|
#[test]
|
|
fn validate_rejects_invalid() {
|
|
let err = args_with_action("start").validate().unwrap_err();
|
|
assert!(err.to_string().contains("up or down"));
|
|
}
|
|
}
|