Skip to content

Commit

Permalink
Change the --assume-in-transaction CLI flag
Browse files Browse the repository at this point in the history
Previously, this could only be specified with a value:

--assume-in-transaction=true
--assume-in-transaction=false

I found prior art [1] for doing a boolean flag in structopt using two
fields. It isn't as elegant as I would have hoped for, but one can now
use:

--assume-in-transaction
--no-assume-in-transaction

which is more common in my experience.

[1]: TeXitoi/structopt#280.
  • Loading branch information
andrewsmith committed Jan 20, 2023
1 parent a396271 commit 07506a7
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fn exit<E: std::fmt::Display, T>(res: Result<T, E>, msg: &str) -> ! {
}

/// Find problems in your SQL
#[allow(clippy::struct_excessive_bools)]
#[derive(StructOpt, Debug)]
struct Opt {
/// Paths to search
Expand Down Expand Up @@ -79,9 +80,13 @@ struct Opt {
/// Path to the squawk config file (.squawk.toml)
#[structopt(short = "c", long = "config")]
config_path: Option<PathBuf>,
/// Assume that a transaction will wrap SQL files when run by a migration tool
#[structopt(long, possible_values = &["true", "false"])]
assume_in_transaction: Option<bool>,
/// Assume that a transaction will wrap each SQL file when run by a migration tool
///
/// Use --no-assume-in-transaction to override any config file that sets this
#[structopt(long)]
assume_in_transaction: bool,
#[structopt(long, hidden = true, conflicts_with = "assume-in-transaction")]
no_assume_in_transaction: bool,
}

#[allow(clippy::too_many_lines)]
Expand Down Expand Up @@ -118,8 +123,10 @@ fn main() {
conf.pg_version
};

let assume_in_transaction = if let Some(assume_in_transaction) = opts.assume_in_transaction {
assume_in_transaction
let assume_in_transaction = if opts.assume_in_transaction {
opts.assume_in_transaction
} else if opts.no_assume_in_transaction {
!opts.no_assume_in_transaction
} else if let Some(assume_in_transaction) = conf.assume_in_transaction {
assume_in_transaction
} else {
Expand Down

0 comments on commit 07506a7

Please sign in to comment.