diff --git a/Cargo.lock b/Cargo.lock index e0c45040..d353fd07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -36,15 +36,6 @@ dependencies = [ "unicode-width 0.2.1", ] -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - [[package]] name = "anstream" version = "0.6.20" @@ -101,17 +92,6 @@ version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100" -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.5.0" @@ -170,7 +150,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.106", + "syn", "which", ] @@ -254,21 +234,6 @@ dependencies = [ "libloading", ] -[[package]] -name = "clap" -version = "2.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" -dependencies = [ - "ansi_term", - "atty", - "bitflags 1.3.2", - "strsim 0.8.0", - "textwrap", - "unicode-width 0.1.14", - "vec_map", -] - [[package]] name = "clap" version = "4.5.46" @@ -288,7 +253,7 @@ dependencies = [ "anstream", "anstyle", "clap_lex", - "strsim 0.11.1", + "strsim", ] [[package]] @@ -297,10 +262,10 @@ version = "4.5.45" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14cb31bb0a7d536caef2639baa7fad459e15c3144efefa6dbd1c84562c4739f6" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -437,7 +402,7 @@ dependencies = [ "glob", "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -448,7 +413,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -501,7 +466,7 @@ checksum = "a1ab991c1362ac86c61ab6f556cff143daa22e5a15e4e189df818b2fd19fe65b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -684,30 +649,12 @@ version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" -[[package]] -name = "heck" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "heck" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "home" version = "0.5.11" @@ -1259,7 +1206,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -1380,31 +1327,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" dependencies = [ "proc-macro2", - "syn 2.0.106", -] - -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", + "syn", ] [[package]] @@ -1432,7 +1355,7 @@ version = "0.13.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be769465445e8c1474e9c5dac2018218498557af32d9ed057325ec9a41ae81bf" dependencies = [ - "heck 0.5.0", + "heck", "itertools 0.14.0", "log", "multimap", @@ -1442,7 +1365,7 @@ dependencies = [ "prost", "prost-types", "regex", - "syn 2.0.106", + "syn", "tempfile", ] @@ -1456,7 +1379,7 @@ dependencies = [ "itertools 0.14.0", "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -1707,7 +1630,7 @@ checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -1739,7 +1662,7 @@ checksum = "175ee3e80ae9982737ca543e96133087cbd9a485eecc3bc4de9c1a37b47ea59c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -1838,6 +1761,7 @@ dependencies = [ "annotate-snippets", "anyhow", "base64 0.12.3", + "clap", "console 0.11.3", "enum-iterator", "glob", @@ -1854,7 +1778,6 @@ dependencies = [ "squawk_linter", "squawk_server", "squawk_syntax", - "structopt", "tempfile", "toml", ] @@ -1958,53 +1881,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" -[[package]] -name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - [[package]] name = "strsim" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" -[[package]] -name = "structopt" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" -dependencies = [ - "clap 2.34.0", - "lazy_static", - "structopt-derive", -] - -[[package]] -name = "structopt-derive" -version = "0.4.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" -dependencies = [ - "heck 0.3.3", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - [[package]] name = "syn" version = "2.0.106" @@ -2030,7 +1912,7 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -2101,15 +1983,6 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f18aa187839b2bdb1ad2fa35ead8c4c2976b64e4363c386d45ac0f7ee85c9233" -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width 0.1.14", -] - [[package]] name = "thiserror" version = "1.0.69" @@ -2136,7 +2009,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -2147,7 +2020,7 @@ checksum = "6c5e1be1c48b9172ee610da68fd9cd2770e7a4056cb3fc98710ee6906f0c7960" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -2339,18 +2212,6 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - [[package]] name = "walkdir" version = "2.5.0" @@ -2407,7 +2268,7 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn 2.0.106", + "syn", "wasm-bindgen-shared", ] @@ -2442,7 +2303,7 @@ checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2477,7 +2338,7 @@ checksum = "17d5042cc5fa009658f9a7333ef24291b1291a25b6382dd68862a7f3b969f69b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] [[package]] @@ -2804,7 +2665,7 @@ version = "2.25.1" dependencies = [ "anyhow", "camino", - "clap 4.5.46", + "clap", "convert_case", "enum-iterator", "proc-macro2", @@ -2837,7 +2698,7 @@ checksum = "38da3c9736e16c5d3c8c597a9aaa5d1fa565d0532ae05e27c24aa62fb32c0ab6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", "synstructure", ] @@ -2858,7 +2719,7 @@ checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", "synstructure", ] @@ -2892,5 +2753,5 @@ checksum = "5b96237efa0c878c64bd89c436f661be4e46b2f3eff1ebb976f7ef2321d2f58f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.106", + "syn", ] diff --git a/Cargo.toml b/Cargo.toml index bf9bb5dd..cd643381 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,6 @@ serde_plain = "1.0" serde_repr = "0.1" regex = "1.11.1" simplelog = "0.12.0" -structopt = "0.3" tempfile = "3.21.0" toml = "0.5.9" dir-test = "0.4" @@ -47,7 +46,7 @@ console_log = "1.0.0" annotate-snippets = "0.11.5" anyhow = "1.0.94" convert_case = "0.7.1" -clap = { version = "4.5.8", features = ["derive"] } +clap = { version = "4.5.8", features = ["derive", "env"] } ungrammar = "1.1.4" quote = "1.0.40" xshell = "0.2.7" diff --git a/crates/squawk/Cargo.toml b/crates/squawk/Cargo.toml index 0b6daf1f..05d26273 100644 --- a/crates/squawk/Cargo.toml +++ b/crates/squawk/Cargo.toml @@ -19,7 +19,7 @@ categories = ["command-line-utilities", "development-tools"] serde_json.workspace = true tempfile.workspace = true serde.workspace = true -structopt.workspace = true +clap.workspace = true console.workspace = true base64.workspace = true simplelog.workspace = true diff --git a/crates/squawk/src/main.rs b/crates/squawk/src/main.rs index 4e9e3940..a531abcf 100644 --- a/crates/squawk/src/main.rs +++ b/crates/squawk/src/main.rs @@ -4,60 +4,58 @@ mod file; mod file_finding; mod github; mod reporter; -use anyhow::{Context, Result}; -use debug::debug; -use reporter::check_and_dump_files; -use squawk_linter::{Rule, Version}; -use structopt::clap::arg_enum; - use crate::file_finding::find_paths; +use anyhow::{Context, Result}; +use clap::{CommandFactory, Parser, Subcommand, ValueEnum}; use config::Config; +use debug::debug; use log::info; +use reporter::check_and_dump_files; use simplelog::CombinedLogger; +use squawk_linter::{Rule, Version}; use std::io; use std::io::IsTerminal; use std::panic; use std::path::PathBuf; use std::process::{self, ExitCode}; -use structopt::StructOpt; -#[derive(StructOpt, Debug)] +#[derive(Parser, Debug)] pub struct UploadToGithubArgs { /// Paths to search paths: Vec, /// Exits with an error if violations are found - #[structopt(long)] + #[arg(long)] fail_on_violations: bool, - #[structopt(long, env = "SQUAWK_GITHUB_PRIVATE_KEY")] + #[arg(long, env = "SQUAWK_GITHUB_PRIVATE_KEY")] github_private_key: Option, - #[structopt(long, env = "SQUAWK_GITHUB_PRIVATE_KEY_BASE64")] + #[arg(long, env = "SQUAWK_GITHUB_PRIVATE_KEY_BASE64")] github_private_key_base64: Option, /// GitHub API url. - #[structopt(long, env = "SQUAWK_GITHUB_API_URL")] + #[arg(long, env = "SQUAWK_GITHUB_API_URL")] github_api_url: Option, - #[structopt(long, env = "SQUAWK_GITHUB_TOKEN")] + #[arg(long, env = "SQUAWK_GITHUB_TOKEN")] github_token: Option, /// GitHub App Id. - #[structopt(long, env = "SQUAWK_GITHUB_APP_ID")] + #[arg(long, env = "SQUAWK_GITHUB_APP_ID")] github_app_id: Option, /// GitHub Install Id. The installation that squawk is acting on. - #[structopt(long, env = "SQUAWK_GITHUB_INSTALL_ID")] + #[arg(long, env = "SQUAWK_GITHUB_INSTALL_ID")] github_install_id: Option, /// GitHub Repo Owner /// github.com/sbdchd/squawk, sbdchd is the owner - #[structopt(long, env = "SQUAWK_GITHUB_REPO_OWNER")] + #[arg(long, env = "SQUAWK_GITHUB_REPO_OWNER")] github_repo_owner: String, /// GitHub Repo Name /// github.com/sbdchd/squawk, squawk is the name - #[structopt(long, env = "SQUAWK_GITHUB_REPO_NAME")] + #[arg(long, env = "SQUAWK_GITHUB_REPO_NAME")] github_repo_name: String, /// GitHub Pull Request Number /// github.com/sbdchd/squawk/pull/10, 10 is the PR number - #[structopt(long, env = "SQUAWK_GITHUB_PR_NUMBER")] + #[arg(long, env = "SQUAWK_GITHUB_PR_NUMBER")] github_pr_number: i64, } -#[derive(StructOpt, Debug)] +#[derive(Subcommand, Debug)] pub enum Command { /// Run the language server Server, @@ -65,31 +63,28 @@ pub enum Command { UploadToGithub(UploadToGithubArgs), } -arg_enum! { - #[derive(Debug, StructOpt)] - pub enum DebugOption { - Lex, - Parse, - Ast - } +#[derive(Debug, ValueEnum, Clone)] +pub enum DebugOption { + Lex, + Parse, + Ast, } -arg_enum! { - #[derive(Debug, StructOpt)] - pub enum Reporter { - Tty, - Gcc, - Json, - Gitlab, - } +#[derive(Debug, ValueEnum, Clone)] +pub enum Reporter { + Tty, + Gcc, + Json, + Gitlab, } /// Find problems in your SQL #[allow(clippy::struct_excessive_bools)] -#[derive(StructOpt, Debug)] +#[derive(Parser, Debug)] +#[command(version)] struct Opt { /// Paths or patterns to search - #[structopt(value_name = "path")] + #[arg(value_name = "path")] path_patterns: Vec, /// Paths to exclude /// @@ -98,17 +93,17 @@ struct Opt { /// `--exclude-path=005_user_ids.sql --exclude-path=009_account_emails.sql` /// /// `--exclude-path='*user_ids.sql'` - #[structopt(long = "exclude-path", global = true)] + #[arg(long = "exclude-path", global = true)] excluded_path: Option>, /// Exclude specific warnings /// /// For example: /// --exclude=require-concurrent-index-creation,ban-drop-database - #[structopt( - short = "e", + #[arg( + short = 'e', long = "exclude", value_name = "rule", - use_delimiter = true, + value_delimiter = ',', global = true )] excluded_rules: Option>, @@ -116,39 +111,39 @@ struct Opt { /// /// For example: /// --pg-version=13.0 - #[structopt(long, global = true)] + #[arg(long, global = true)] pg_version: Option, /// Output debug format - #[structopt(long,value_name ="format", possible_values = &DebugOption::variants(), case_insensitive = true)] + #[arg(long, value_name = "format", ignore_case = true)] debug: Option, /// Style of error reporting - #[structopt(long, possible_values = &Reporter::variants(), case_insensitive = true)] + #[arg(long, ignore_case = true)] reporter: Option, - #[structopt(long, value_name = "filepath")] + #[arg(long, value_name = "filepath")] /// Path to use in reporting for stdin stdin_filepath: Option, - #[structopt(subcommand)] + #[command(subcommand)] cmd: Option, /// Enable debug logging output - #[structopt(long, global = true)] + #[arg(long, global = true)] verbose: bool, /// Path to the squawk config file (.squawk.toml) - #[structopt(short = "c", long = "config", global = true)] + #[arg(short = 'c', long = "config", global = true)] config_path: Option, /// 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, global = true)] + #[arg(long, global = true)] assume_in_transaction: bool, - #[structopt( + #[arg( long, - hidden = true, - conflicts_with = "assume-in-transaction", + hide = true, + conflicts_with = "assume_in_transaction", global = true )] no_assume_in_transaction: bool, /// Do not exit with an error when provided path patterns do not match any files - #[structopt(long = "no-error-on-unmatched-pattern", global = true)] + #[arg(long = "no-error-on-unmatched-pattern", global = true)] no_error_on_unmatched_pattern: bool, } @@ -170,7 +165,7 @@ Please open an issue at https://github.com/sbdchd/squawk/issues/new with the log writeln!(stderr, "{panic_info}\n{backtrace}\n{open_an_issue}").ok(); })); - let opts = Opt::from_args(); + let opts = Opt::parse(); if opts.verbose { CombinedLogger::init(vec![simplelog::TermLogger::new( @@ -228,7 +223,6 @@ Please open an issue at https://github.com/sbdchd/squawk/issues/new with the log info!("assume in a transaction: {assume_in_transaction:?}"); info!("no error on unmatched pattern: {no_error_on_unmatched_pattern:?}"); - let mut clap_app = Opt::clap(); let is_stdin = !io::stdin().is_terminal(); let github_annotations = std::env::var("GITHUB_ACTIONS").is_ok() && std::env::var("SQUAWK_DISABLE_GITHUB_ANNOTATIONS").is_err(); @@ -288,7 +282,7 @@ Please open an issue at https://github.com/sbdchd/squawk/issues/new with the log return Ok(exit_code); } } else if !no_error_on_unmatched_pattern { - clap_app.print_long_help()?; + Opt::command().print_long_help()?; println!(); } } diff --git a/crates/squawk_linter/src/lib.rs b/crates/squawk_linter/src/lib.rs index 710ae4f2..85d09afb 100644 --- a/crates/squawk_linter/src/lib.rs +++ b/crates/squawk_linter/src/lib.rs @@ -171,6 +171,8 @@ impl std::fmt::Display for UnknownRuleName { } } +impl std::error::Error for UnknownRuleName {} + impl std::str::FromStr for Rule { type Err = UnknownRuleName; fn from_str(s: &str) -> Result { diff --git a/crates/squawk_linter/src/version.rs b/crates/squawk_linter/src/version.rs index 268b5e93..dbf2caaa 100644 --- a/crates/squawk_linter/src/version.rs +++ b/crates/squawk_linter/src/version.rs @@ -86,6 +86,8 @@ impl std::fmt::Display for ParseVersionError { } } +impl std::error::Error for ParseVersionError {} + impl FromStr for Version { type Err = ParseVersionError;