Skip to content

Commit

Permalink
Fix --uppercase=false not working
Browse files Browse the repository at this point in the history
Closes #16
Fixes the value of the uppercase option always being true.
This was due to the design of claps boolean flags which is
discussed here:
clap-rs/clap#1649 (comment)
This PR uses the solution mentioned in the linked comment from
that thread.

Using `require_equals` and `default_missing_value` allows
`sleek --uppercase "queries/*sql"` to still work without
trying to parse the path as the uppercase boolean, reducing
breakage.

Use `--uppercase=false` to disable uppercase, NOT `--uppercase false`.
  • Loading branch information
paul-hansen committed Jan 20, 2024
1 parent 8784325 commit 25ecfd4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::io::{Read, Write};
use std::process;
use std::{fs, io};

use clap::{crate_version, Parser};
use clap::{crate_version, ArgAction, Parser};
use glob::glob;
use sqlformat::{format, FormatOptions, Indent, QueryParams};
use thiserror::Error;
Expand Down Expand Up @@ -99,7 +99,15 @@ struct Options {
#[clap(short, long, default_value = "4")]
indent_spaces: u8,
/// Change reserved keywords to ALL CAPS
#[clap(short = 'U', long, default_value = "true")]
#[clap(
short = 'U',
long,
default_value("true"),
default_missing_value("true"),
require_equals(true),
num_args(0..=1),
action = ArgAction::Set
)]
uppercase: bool,
/// Set the number of line breaks after a query
#[clap(short, long, default_value = "2")]
Expand Down

0 comments on commit 25ecfd4

Please sign in to comment.