Merge pull request #2178 from influxdata/crepererum/fix_yesno_flag

fix: fix skip replay env flag
pull/24376/head
kodiakhq[bot] 2021-08-03 16:19:55 +00:00 committed by GitHub
commit e3e32ccbcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 3 deletions

View File

@ -26,6 +26,36 @@ pub enum Error {
pub type Result<T, E = Error> = std::result::Result<T, E>;
/// Boolean flag that works with environment variables.
///
/// Workaround for <https://github.com/TeXitoi/structopt/issues/428>
#[derive(Debug)]
pub enum BooleanFlag {
True,
False,
}
impl std::str::FromStr for BooleanFlag {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_ascii_lowercase().as_str() {
"yes" | "y" | "true" | "t" | "1" => Ok(Self::True),
"no" | "n" | "false" | "f" | "0" => Ok(Self::False),
_ => Err(format!(
"Invalid boolean flag '{}'. Valid options: yes, no, y, n, true, false, t, f, 1, 0",
s
)),
}
}
}
impl From<BooleanFlag> for bool {
fn from(yes_no: BooleanFlag) -> Self {
matches!(yes_no, BooleanFlag::True)
}
}
#[derive(Debug, StructOpt)]
#[structopt(
name = "run",
@ -241,8 +271,12 @@ Possible values (case insensitive):
pub max_http_request_size: usize,
/// Skip replaying the write buffer and seek to high watermark instead.
#[structopt(long = "--skip-replay", env = "IOX_SKIP_REPLAY")]
pub skip_replay_and_seek_instead: bool,
#[structopt(
long = "--skip-replay",
env = "INFLUXDB_IOX_SKIP_REPLAY",
default_value = "no"
)]
pub skip_replay_and_seek_instead: BooleanFlag,
}
pub async fn command(config: Config) -> Result<()> {

View File

@ -146,7 +146,7 @@ pub async fn main(config: Config) -> Result<()> {
remote_template: config.remote_template.map(RemoteTemplate::new),
// TODO: Don't wipe on error (#1522)
wipe_catalog_on_error: true,
skip_replay_and_seek_instead: config.skip_replay_and_seek_instead,
skip_replay_and_seek_instead: config.skip_replay_and_seek_instead.into(),
};
if config.grpc_bind_address == config.http_bind_address {