From 420b1acea1f977aa45712ca22309fad20a5a6018 Mon Sep 17 00:00:00 2001 From: nickelc Date: Fri, 3 Mar 2023 12:19:07 +0100 Subject: Update `clap` to 4.1 (#1322) * Update to clap 4 * Add help, usage, error-context features to clap * Add wrap_help clap feature * Remove DeriveDisplayOrder as it is now default * Update ValueSource using statement * Update #[clap(...)] to #[command(...)] * Update #[clap(...)] to #[arg(...)] * Update #[structopt(...)] to #[arg(...)] * Remove value_parser because it is now default * Return option & argument names as `String` due to lifetime issues * Remove leading hyphens from arguments long definition Leading hyphens are no longer accepted. * Argument names are derived from field names and `snake_case` * `help` & `version` are no longer added automatically * Update `clap` to 4.1.8 --------- Co-authored-by: tjquillan --- Cargo.lock | 182 +++++++++++++++++++++++++++++++++++++----- Cargo.toml | 2 +- src/cli.rs | 228 ++++++++++++++++++++++++++--------------------------- src/config.rs | 2 +- src/options/set.rs | 25 +++--- 5 files changed, 292 insertions(+), 147 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f926d3ae..6c04f0b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -56,7 +56,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.17", "libc", "winapi", ] @@ -211,26 +211,25 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.8" +version = "4.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190814073e85d238f31ff738fcb0bf6910cedeb73376c87cd69291028966fd83" +checksum = "c3d7ae14b20b94cb02149ed21a86c423859cbe18dc7ed69845cace50e52b40a5" dependencies = [ - "atty", "bitflags", "clap_derive", "clap_lex", - "indexmap", + "is-terminal", "once_cell", "strsim", "termcolor", - "textwrap", + "terminal_size 0.2.5", ] [[package]] name = "clap_derive" -version = "3.2.7" +version = "4.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "759bf187376e1afa7b85b959e6a664a3e7a95203415dba952ad19139e798f902" +checksum = "44bec8e5c9d09e439c4335b1af0abaab56dcf3b94999a936e1bb47b9134288f0" dependencies = [ "heck", "proc-macro-error", @@ -241,9 +240,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.2.4" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +checksum = "350b9cf31731f9957399229e9b2adc51eeabdfbe9d71d9a0552275fd12710d09" dependencies = [ "os_str_bytes", ] @@ -270,7 +269,7 @@ dependencies = [ "libc", "once_cell", "regex", - "terminal_size", + "terminal_size 0.1.15", "unicode-width", "winapi", ] @@ -426,6 +425,27 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569" +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "error-chain" version = "0.12.4" @@ -687,6 +707,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + [[package]] name = "idna" version = "0.2.0" @@ -708,6 +734,28 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "io-lifetimes" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "is-terminal" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b6b32576413a8e69b90e952e4a026476040d81017b80445deda5f2d3921857" +dependencies = [ + "hermit-abi 0.3.1", + "io-lifetimes", + "rustix", + "windows-sys", +] + [[package]] name = "itertools" version = "0.10.3" @@ -740,9 +788,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.138" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" [[package]] name = "libgit2-sys" @@ -783,6 +831,12 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8dd5a6d5999d9907cda8ed67bbd137d3af8085216c2ac62de5be860bd41f304a" +[[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" + [[package]] name = "log" version = "0.4.11" @@ -1055,11 +1109,11 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro2" -version = "1.0.36" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] @@ -1178,6 +1232,20 @@ dependencies = [ "bytemuck", ] +[[package]] +name = "rustix" +version = "0.36.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "ryu" version = "1.0.5" @@ -1355,10 +1423,14 @@ dependencies = [ ] [[package]] -name = "textwrap" -version = "0.15.0" +name = "terminal_size" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" +checksum = "4c9afddd2cec1c0909f06b00ef33f94ab2cc0578c4a610aa208ddfec8aa2b43a" +dependencies = [ + "rustix", + "windows-sys", +] [[package]] name = "thiserror" @@ -1446,6 +1518,12 @@ dependencies = [ "matches", ] +[[package]] +name = "unicode-ident" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" + [[package]] name = "unicode-normalization" version = "0.1.16" @@ -1578,6 +1656,72 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" + [[package]] name = "xdg" version = "2.4.1" diff --git a/Cargo.toml b/Cargo.toml index 18f9e9c3..d144542d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ atty = "0.2.14" bitflags = "1.3.2" box_drawing = "0.1.2" bytelines = "2.4.0" -clap = { version = "3.2.8", features = ["derive"] } +clap = { version = "4.1.8", features = ["derive", "help", "usage", "error-context", "wrap_help"] } console = "0.15.0" ctrlc = "3.2.2" dirs-next = "2.0.0" diff --git a/src/cli.rs b/src/cli.rs index f8b29842..fc959e2c 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -3,7 +3,7 @@ use std::ffi::OsString; use std::path::PathBuf; use bat::assets::HighlightingAssets; -use clap::{AppSettings, ColorChoice, CommandFactory, FromArgMatches, Parser}; +use clap::{ColorChoice, CommandFactory, FromArgMatches, Parser}; use lazy_static::lazy_static; use syntect::highlighting::Theme as SyntaxTheme; use syntect::parsing::SyntaxSet; @@ -16,12 +16,11 @@ use crate::utils; use crate::utils::bat::output::PagingMode; #[derive(Parser)] -#[clap( +#[command( name = "delta", about = "A viewer for git and diff output", version, color = ColorChoice::Always, - setting(AppSettings::DeriveDisplayOrder), term_width(0), after_long_help = "\ GIT CONFIG @@ -208,7 +207,7 @@ For a short help summary, please use delta -h. " )] pub struct Opt { - #[clap(long = "blame-code-style", value_name = "STYLE")] + #[arg(long = "blame-code-style", value_name = "STYLE")] /// Style string for the code section of a git blame line. /// /// By default the code will be syntax-highlighted with the same background color as the blame @@ -216,7 +215,7 @@ pub struct Opt { /// setting this option to 'syntax' will syntax-highlight the code with no background color. pub blame_code_style: Option, - #[clap( + #[arg( long = "blame-format", default_value = "{timestamp:<15} {author:<15.14} {commit:<8}", value_name = "FMT" @@ -226,14 +225,14 @@ pub struct Opt { /// Available placeholders are "{timestamp}", "{author}", and "{commit}". pub blame_format: String, - #[clap(long = "blame-palette", value_name = "COLORS")] + #[arg(long = "blame-palette", value_name = "COLORS")] /// Background colors used for git blame lines (space-separated string). /// /// Lines added by the same commit are painted with the same color; colors are recycled as /// needed. pub blame_palette: Option, - #[clap( + #[arg( long = "blame-separator-format", default_value = "│{n:^4}│", value_name = "FMT" @@ -248,11 +247,11 @@ pub struct Opt { /// N-th (modulo) line. pub blame_separator_format: String, - #[clap(long = "blame-separator-style", value_name = "STYLE")] + #[arg(long = "blame-separator-style", value_name = "STYLE")] /// Style string for the blame-separator-format. pub blame_separator_style: Option, - #[clap( + #[arg( long = "blame-timestamp-format", default_value = "%Y-%m-%d %H:%M:%S %z", value_name = "FMT" @@ -260,7 +259,7 @@ pub struct Opt { /// Format of `git blame` timestamp in raw git output received by delta. pub blame_timestamp_format: String, - #[clap(long = "blame-timestamp-output-format", value_name = "FMT")] + #[arg(long = "blame-timestamp-output-format", value_name = "FMT")] /// Format string for git blame timestamp output. /// /// This string is used for formatting the timestamps in git blame output. It must follow @@ -270,14 +269,14 @@ pub struct Opt { /// See: (https://docs.rs/chrono/latest/chrono/format/strftime/index.html) pub blame_timestamp_output_format: Option, - #[clap(long = "color-only")] + #[arg(long = "color-only")] /// Do not alter the input structurally in any way. /// /// But color and highlight hunk lines according to your delta configuration. This is mainly /// intended for other tools that use delta. pub color_only: bool, - #[clap( + #[arg( long = "commit-decoration-style", default_value = "", value_name = "STYLE" @@ -288,7 +287,7 @@ pub struct Opt { /// 'ul' (underline), 'ol' (overline), or the combination 'ul ol'. pub commit_decoration_style: String, - #[clap( + #[arg( long = "commit-regex", default_value = r"^commit ", value_name = "REGEX" @@ -296,45 +295,45 @@ pub struct Opt { /// Regular expression used to identify the commit line when parsing git output. pub commit_regex: String, - #[clap(long = "commit-style", default_value = "raw", value_name = "STYLE")] + #[arg(long = "commit-style", default_value = "raw", value_name = "STYLE")] /// Style string for the commit hash line. /// /// See STYLES section. The style 'omit' can be used to remove the commit hash line from the /// output. pub commit_style: String, - #[clap(long = "dark")] + #[arg(long = "dark")] /// Use default colors appropriate for a dark terminal background. /// /// For more control, see the style options and --syntax-theme. pub dark: bool, - #[clap(long = "default-language", value_name = "LANG")] + #[arg(long = "default-language", value_name = "LANG")] /// Default language used for syntax highlighting. /// /// Used when the language cannot be inferred from a filename. It will typically make sense to /// set this in per-repository git config (.git/config) pub default_language: Option, - #[clap(long = "diff-highlight")] + #[arg(long = "diff-highlight")] /// Emulate diff-highlight. /// /// (https://github.com/git/git/tree/master/contrib/diff-highlight) pub diff_highlight: bool, - #[clap(long = "diff-so-fancy")] + #[arg(long = "diff-so-fancy")] /// Emulate diff-so-fancy. /// /// (https://github.com/so-fancy/diff-so-fancy) pub diff_so_fancy: bool, - #[clap(long = "diff-stat-align-width", default_value = "48", value_name = "N")] + #[arg(long = "diff-stat-align-width", default_value = "48", value_name = "N")] /// Width allocated for file paths in a diff stat section. /// /// If a relativized file path exceeds this width then the diff stat will be misaligned. pub diff_stat_align_width: usize, - #[clap(long = "features", value_name = "FEATURES")] + #[arg(long = "features", value_name = "FEATURES")] /// Names of delta features to activate (space-separated). /// /// A feature is a named collection of delta options in ~/.gitconfig. See FEATURES section. The @@ -344,7 +343,7 @@ pub struct Opt { /// side-by-side temporarily (use DELTA_FEATURES=+ to go back to just the features from git config). pub features: Option, - #[clap( + #[arg( long = "file-added-label", default_value = "added:", value_name = "STRING" @@ -354,7 +353,7 @@ pub struct Opt { /// Used in the default value of navigate-regex. pub file_added_label: String, - #[clap( + #[arg( long = "file-copied-label", default_value = "copied:", value_name = "STRING" @@ -362,7 +361,7 @@ pub struct Opt { /// Text to display before a copied file path. pub file_copied_label: String, - #[clap( + #[arg( long = "file-decoration-style", default_value = "blue ul", value_name = "STYLE" @@ -373,7 +372,7 @@ pub struct Opt { /// 'ul' (underline), 'ol' (overline), or the combination 'ul ol'. pub file_decoration_style: String, - #[clap( + #[arg( long = "file-modified-label", default_value = "", value_name = "STRING" @@ -383,7 +382,7 @@ pub struct Opt { /// Used in the default value of navigate-regex. pub file_modified_label: String, - #[clap( + #[arg( long = "file-removed-label", default_value = "removed:", value_name = "STRING" @@ -393,7 +392,7 @@ pub struct Opt { /// Used in the default value of navigate-regex. pub file_removed_label: String, - #[clap( + #[arg( long = "file-renamed-label", default_value = "renamed:", value_name = "STRING" @@ -403,47 +402,47 @@ pub struct Opt { /// Used in the default value of navigate-regex. pub file_renamed_label: String, - #[clap(long = "file-style", default_value = "blue", value_name = "STYLE")] + #[arg(long = "file-style", default_value = "blue", value_name = "STYLE")] /// Style string for the file section. /// /// See STYLES section. The style 'omit' can be used to remove the file section from the output. pub file_style: String, - #[structopt(long = "file-transformation", value_name = "SED_CMD")] + #[arg(long = "file-transformation", value_name = "SED_CMD")] /// Sed-style command transforming file paths for display. pub file_regex_replacement: Option, - #[clap(long = "grep-context-line-style", value_name = "STYLE")] + #[arg(long = "grep-context-line-style", value_name = "STYLE")] /// Style string for non-matching lines of grep output. /// /// See STYLES section. Defaults to zero-style. pub grep_context_line_style: Option, - #[clap(long = "grep-file-style", value_name = "STYLE")] + #[arg(long = "grep-file-style", value_name = "STYLE")] /// Style string for file paths in grep output. /// /// See STYLES section. Defaults to hunk-header-file-path-style. pub grep_file_style: Option, - #[clap(long = "grep-line-number-style", value_name = "STYLE")] + #[arg(long = "grep-line-number-style", value_name = "STYLE")] /// Style string for line numbers in grep output. /// /// See STYLES section. Defaults to hunk-header-line-number-style. pub grep_line_number_style: Option, - #[clap(long = "grep-match-line-style", value_name = "STYLE")] + #[arg(long = "grep-match-line-style", value_name = "STYLE")] /// Style string for matching lines of grep output. /// /// See STYLES section. Defaults to plus-style. pub grep_match_line_style: Option, - #[clap(long = "grep-match-word-style", value_name = "STYLE")] + #[arg(long = "grep-match-word-style", value_name = "STYLE")] /// Style string for the matching substrings within a matching line of grep output. /// /// See STYLES section. Defaults to plus-style. pub grep_match_word_style: Option, - #[clap( + #[arg( long = "grep-separator-symbol", default_value = ":", value_name = "STRING" @@ -455,7 +454,7 @@ pub struct Opt { /// lines: set this option to "keep" to keep the original separator symbols. pub grep_separator_symbol: String, - #[clap( + #[arg( long = "hunk-header-decoration-style", default_value = "blue box", value_name = "STYLE" @@ -466,7 +465,7 @@ pub struct Opt { /// 'ul' (underline), 'ol' (overline), or the combination 'ul ol'. pub hunk_header_decoration_style: String, - #[clap( + #[arg( long = "hunk-header-file-style", default_value = "blue", value_name = "STYLE" @@ -477,7 +476,7 @@ pub struct Opt { /// 'file' special attribute. pub hunk_header_file_style: String, - #[clap( + #[arg( long = "hunk-header-line-number-style", default_value = "blue", value_name = "STYLE" @@ -488,7 +487,7 @@ pub struct Opt { /// 'line-number' special attribute. pub hunk_header_line_number_style: String, - #[clap( + #[arg( long = "hunk-header-style", default_value = "line-number syntax", value_name = "STYLE" @@ -500,13 +499,13 @@ pub struct Opt { /// to remove the hunk header section from the output. pub hunk_header_style: String, - #[clap(long = "hunk-label", default_value = "", value_name = "STRING")] + #[arg(long = "hunk-label", default_value = "", value_name = "STRING")] /// Text to display before a hunk header. /// /// Used in the default value of navigate-regex. pub hunk_label: String, - #[clap(long = "hyperlinks")] + #[arg(long = "hyperlinks")] /// Render commit hashes, file names, and line numbers as hyperlinks. /// /// Following the hyperlink spec for terminal emulators: @@ -520,14 +519,14 @@ pub struct Opt { /// https://github.com/dandavison/tmux). pub hyperlinks: bool, - #[clap(long = "hyperlinks-commit-link-format", value_name = "FMT")] + #[arg(long = "hyperlinks-commit-link-format", value_name = "FMT")] /// Format string for commit hyperlinks (requires --hyperlinks). /// /// The placeholder "{commit}" will be replaced by the commit hash. For example: /// --hyperlinks-commit-link-format='https://mygitrepo/{commit}/' pub hyperlinks_commit_link_format: Option, - #[clap( + #[arg( long = "hyperlinks-file-link-format", default_value = "file://{path}", value_name = "FMT" @@ -544,7 +543,7 @@ pub struct Opt { /// https://github.com/dandavison/open-in-editor for an example. pub hyperlinks_file_link_format: String, - #[clap( + #[arg( long = "inline-hint-style", default_value = "blue", value_name = "STYLE" @@ -555,7 +554,7 @@ pub struct Opt { /// to highlight tabs, and the symbols used to indicate wrapped lines. See STYLES section. pub inline_hint_style: String, - #[clap( + #[arg( long = "inspect-raw-lines", default_value = "true", value_name = "true|false" @@ -567,20 +566,20 @@ pub struct Opt { /// Git's --color-moved feature. Set this to "false" to disable this behavior. pub inspect_raw_lines: String, - #[clap(long = "keep-plus-minus-markers")] + #[arg(long = "keep-plus-minus-markers")] /// Prefix added/removed lines with a +/- character, as git does. /// /// By default, delta does not emit any prefix, so code can be copied directly from delta's /// output. pub keep_plus_minus_markers: bool, - #[clap(long = "light")] + #[arg(long = "light")] /// Use default colors appropriate for a light terminal background. /// /// For more control, see the style options and --syntax-theme. pub light: bool, - #[clap(long = "line-buffer-size", default_value = "32", value_name = "N")] + #[arg(long = "line-buffer-size", default_value = "32", value_name = "N")] /// Size of internal line buffer. /// /// Delta compares the added and removed versions of nearby lines in order to detect and @@ -590,7 +589,7 @@ pub struct Opt { /// affect delta's performance when entire files are added/removed. pub line_buffer_size: usize, - #[clap(long = "line-fill-method", value_name = "STRING")] + #[arg(long = "line-fill-method", value_name = "STRING")] /// Line-fill method in side-by-side mode. /// /// How to extend the background color to the end of the line in side-by-side mode. Can be ansi @@ -598,13 +597,13 @@ pub struct Opt { /// --width=variable is given. pub line_fill_method: Option, - #[clap(short = 'n', long = "line-numbers")] + #[arg(short = 'n', long = "line-numbers")] /// Display line numbers next to the diff. /// /// See LINE NUMBERS section. pub line_numbers: bool, - #[clap( + #[arg( long = "line-numbers-left-format", default_value = "{nm:^4}⋮", value_name = "FMT" @@ -616,7 +615,7 @@ pub struct Opt { /// dividing character. See the LINE NUMBERS section. pub line_numbers_left_format: String, - #[clap( + #[arg( long = "line-numbers-left-style", default_value = "auto", value_name = "STYLE" @@ -626,7 +625,7 @@ pub struct Opt { /// See STYLES and LINE NUMBERS sections. pub line_numbers_left_style: String, - #[clap( + #[arg( long = "line-numbers-minus-style", default_value = "auto", value_name = "STYLE" @@ -636,7 +635,7 @@ pub struct Opt { /// See STYLES and LINE NUMBERS sections. pub line_numbers_minus_style: String, - #[clap( + #[arg( long = "line-numbers-plus-style", default_value = "auto", value_name = "STYLE" @@ -646,7 +645,7 @@ pub struct Opt { /// See STYLES and LINE NUMBERS sections. pub line_numbers_plus_style: String, - #[clap( + #[arg( long = "line-numbers-right-format", default_value = "{np:^4}│", value_name = "FMT" @@ -658,7 +657,7 @@ pub struct Opt { /// dividing character, and a space. See the LINE NUMBERS section. pub line_numbers_right_format: String, - #[clap( + #[arg( long = "line-numbers-right-style", default_value = "auto", value_name = "STYLE" @@ -668,7 +667,7 @@ pub struct Opt { /// See STYLES and LINE NUMBERS sections. pub line_numbers_right_style: String, - #[clap( + #[arg( long = "line-numbers-zero-style", default_value = "auto", value_name = "STYLE" @@ -678,21 +677,21 @@ pub struct Opt { /// See STYLES and LINE NUMBERS sections. pub line_numbers_zero_style: String, - #[clap(long = "list-languages")] + #[arg(long = "list-languages")] /// List supported languages and associated file extensions. pub list_languages: bool, - #[clap(long = "list-syntax-themes")] + #[arg(long = "list-syntax-themes")] /// List available syntax-highlighting color themes. pub list_syntax_themes: bool, - #[clap(long = "map-styles", value_name = "STYLES_MAP")] + #[arg(long = "map-styles", value_name = "STYLES_MAP")] /// Map styles encountered in raw input to desired output styles. /// /// An example is --map-styles='bold purple => red "#eeeeee", bold cyan => syntax "#eeeeee"' pub map_styles: Option, - #[clap(long = "max-line-distance", default_value = "0.6", value_name = "DIST")] + #[arg(long = "max-line-distance", default_value = "0.6", value_name = "DIST")] /// Maximum line pair distance parameter in within-line diff algorithm. /// /// This parameter is the maximum distance (0.0 - 1.0) between two lines for them to be inferred @@ -700,7 +699,7 @@ pub struct Opt { /// insertion operations transforming one into the other. pub max_line_distance: f64, - #[clap(long = "max-line-length", default_value = "512", value_name = "N")] + #[arg(long = "max-line-length", default_value = "512", value_name = "N")] /// Truncate lines longer than this. /// /// To prevent any truncation, set to zero. Note that delta will be slow on very long lines @@ -708,7 +707,7 @@ pub struct Opt { /// to fit at least all visible characters. pub max_line_length: usize, - #[clap( + #[arg( long = "merge-conflict-begin-symbol", default_value = "▼", value_name = "STRING" @@ -718,7 +717,7 @@ pub struct Opt { /// The string will be repeated until it reaches the required length. pub merge_conflict_begin_symbol: String, - #[clap( + #[arg( long = "merge-conflict-end-symbol", default_value = "▲", value_name = "STRING" @@ -728,7 +727,7 @@ pub struct Opt { /// The string will be repeated until it reaches the required length. pub merge_conflict_end_symbol: String, - #[clap( + #[arg( long = "merge-conflict-ours-diff-header-decoration-style", default_value = "box", value_name = "STYLE" @@ -740,7 +739,7 @@ pub struct Opt { /// attributes 'box', 'ul' (underline), 'ol' (overline), or the combination 'ul ol'. pub merge_conflict_ours_diff_header_decoration_style: String, - #[clap( + #[arg( long = "merge-conflict-ours-diff-header-style", default_value = "normal", value_name = "STYLE" @@ -750,7 +749,7 @@ pub struct Opt { /// See STYLES section. pub merge_conflict_ours_diff_header_style: String, - #[clap( + #[arg( long = "merge-conflict-theirs-diff-header-decoration-style", default_value = "box", value_name = "STYLE" @@ -762,7 +761,7 @@ pub struct Opt { /// attributes 'box', 'ul' (underline), 'ol' (overline), or the combination 'ul ol'. pub merge_conflict_theirs_diff_header_decoration_style: String, - #[clap( + #[arg( long = "merge-conflict-theirs-diff-header-style", default_value = "normal", value_name = "STYLE" @@ -773,8 +772,8 @@ pub struct Opt { /// STYLES section. pub merge_conflict_theirs_diff_header_style: String, - #[clap( - long = "--minus-empty-line-marker-style", + #[arg( + long = "minus-empty-line-marker-style", default_value = "normal auto", value_name = "STYLE" )] @@ -783,7 +782,7 @@ pub struct Opt { /// Used only if --minus-style has no background color. pub minus_empty_line_marker_style: String, - #[clap( + #[arg( long = "minus-emph-style", default_value = "normal auto", value_name = "STYLE" @@ -793,7 +792,7 @@ pub struct Opt { /// See STYLES section. pub minus_emph_style: String, - #[clap( + #[arg( long = "minus-non-emph-style", default_value = "minus-style", value_name = "STYLE" @@ -803,7 +802,7 @@ pub struct Opt { /// See STYLES section. pub minus_non_emph_style: String, - #[clap( + #[arg( long = "minus-style", default_value = "normal auto", value_name = "STYLE" @@ -813,24 +812,24 @@ pub struct Opt { /// See STYLES section. pub minus_style: String, - #[clap(long = "navigate")] + #[arg(long = "navigate")] /// Activate diff navigation. /// /// Use n to jump forwards and N to jump backwards. To change the file labels used see /// --file-modified-label, --file-removed-label, --file-added-label, --file-renamed-label. pub navigate: bool, - #[clap(long = "navigate-regex", value_name = "REGEX")] + #[arg(long = "navigate-regex", value_name = "REGEX")] /// Regular expression defining navigation stop points. pub navigate_regex: Option, - #[clap(long = "no-gitconfig")] + #[arg(long = "no-gitconfig")] /// Do not read any settings from git config. /// /// See GIT CONFIG section. pub no_gitconfig: bool, - #[clap(long = "pager", value_name = "CMD")] + #[arg(long = "pager", value_name = "CMD")] /// Which pager to use. /// /// The default pager is `less`. You can also change pager by setting the environment variables @@ -838,7 +837,7 @@ pub struct Opt { /// overrides all environment variables above. pub pager: Option, - #[clap( + #[arg( long = "paging", default_value = "auto", value_name = "auto|always|never" @@ -848,14 +847,14 @@ pub struct Opt { /// Options are: auto, always, and never. pub paging_mode: String, - #[clap(long = "parse-ansi")] + #[arg(long = "parse-ansi")] /// Display ANSI color escape sequences in human-readable form. /// /// Example usage: git show --color=always | delta --parse-ansi /// This can be used to help identify input style strings to use with map-styles. pub parse_ansi: bool, - #[clap( + #[arg( long = "plus-emph-style", default_value = "syntax auto", value_name = "STYLE" @@ -865,7 +864,7 @@ pub struct Opt { /// See STYLES section. pub plus_emph_style: String, - #[clap( + #[arg( long = "plus-empty-line-marker-style", default_value = "normal auto", value_name = "STYLE" @@ -875,7 +874,7 @@ pub struct Opt { /// Used only if --plus-style has no background color. pub plus_empty_line_marker_style: String, - #[clap( + #[arg( long = "plus-non-emph-style", default_value = "plus-style", value_name = "STYLE" @@ -885,7 +884,7 @@ pub struct Opt { /// See STYLES section. pub plus_non_emph_style: String, - #[clap( + #[arg( long = "plus-style", default_value = "syntax auto", value_name = "STYLE" @@ -895,32 +894,32 @@ pub struct Opt { /// See STYLES section. pub plus_style: String, - #[clap(long = "raw")] + #[arg(long = "raw")] /// Do not alter the input in any way. /// /// This is mainly intended for testing delta. pub raw: bool, - #[clap(long = "relative-paths")] + #[arg(long = "relative-paths")] /// Output all file paths relative to the current directory. /// /// This means that they will resolve correctly when clicked on or used in shell commands. pub relative_paths: bool, - #[clap(long = "right-arrow", default_value = "⟶ ", value_name = "STRING")] + #[arg(long = "right-arrow", default_value = "⟶ ", value_name = "STRING")] /// Text to display with a changed file path. /// /// For example, a unified diff heading, a rename, or a chmod. pub right_arrow: String, - #[clap(long = "show-colors")] + #[arg(long = "show-colors")] /// Show available named colors. /// /// In addition to named colors, arbitrary colors can be specified using RGB hex codes. See /// COLORS section. pub show_colors: bool, - #[clap(long = "show-config")] + #[arg(long = "show-config")] /// Display the active values for all Delta options. /// /// Style string options are displayed with foreground and background colors. This can be used to @@ -928,14 +927,14 @@ pub struct Opt { /// --zero-style, --plus-style, --light, --dark, etc. pub show_config: bool, - #[clap(long = "show-syntax-themes")] + #[arg(long = "show-syntax-themes")] /// Show example diff for available syntax-highlighting themes. /// /// If diff output is supplied on standard input then this will be used for the demo. For /// example: `git show | delta --show-syntax-themes`. pub show_syntax_themes: bool, - #[clap(long = "show-themes")] + #[arg(long = "show-themes")] /// Show example diff for available delta themes. /// /// A delta theme is a delta named feature (see --features) that sets either `light` or `dark`. @@ -946,11 +945,11 @@ pub struct Opt { /// shown, use --dark or --light, or both, on the command line together with this option. pub show_themes: bool, - #[clap(short = 's', long = "side-by-side")] + #[arg(short = 's', long = "side-by-side")] /// Display diffs in side-by-side layout. pub side_by_side: bool, - #[clap(long = "syntax-theme", value_name = "SYNTAX_THEME")] + #[arg(long = "syntax-theme", value_name = "SYNTAX_THEME")] /// The syntax-highlighting theme to use. /// /// Use --show-syntax-themes to demo available themes. Defaults to the value of the BAT_THEME @@ -958,7 +957,7 @@ pub struct Opt { /// syntax highlighting. pub syntax_theme: Option, - #[clap(long = "tabs", default_value = "4", value_name = "N")] + #[arg(long = "tabs", default_value = "4", value_name = "N")] /// The number of spaces to replace tab characters with. /// /// Use --tabs=0 to pass tab characters through directly, but note that in that case delta will @@ -967,7 +966,7 @@ pub struct Opt { /// incorrect. pub tab_width: usize, - #[clap( + #[arg( long = "true-color", default_value = "auto", value_name = "auto|always|never" @@ -981,7 +980,7 @@ pub struct Opt { /// need to do anything. pub true_color: String, - #[clap( + #[arg( long = "whitespace-error-style", default_value = "auto auto", value_name = "STYLE" @@ -991,7 +990,7 @@ pub struct Opt { /// Defaults to color.diff.whitespace if that is set in git config, or else 'magenta reverse'. pub whitespace_error_style: String, - #[clap(short = 'w', long = "width", value_name = "N")] + #[arg(short = 'w', long = "width", value_name = "N")] /// The width of underline/overline decorations. /// /// Examples: "72" (exactly 72 characters), "-2" (auto-detected terminal width minus 2). An @@ -1001,7 +1000,7 @@ pub struct Opt { /// full terminal width. pub width: Option, - #[clap(long = "word-diff-regex", default_value = r"\w+", value_name = "REGEX")] + #[arg(long = "word-diff-regex", default_value = r"\w+", value_name = "REGEX")] /// Regular expression defining a 'word' in within-line diff algorithm. /// /// The regular expression used to decide what a word is for the within-line highlight @@ -1009,21 +1008,21 @@ pub struct Opt { /// --max-line-distance=1.0 (this is more similar to `git --word-diff`). pub tokenization_regex: String, - #[clap(long = "wrap-left-symbol", default_value = "↵", value_name = "STRING")] + #[arg(long = "wrap-left-symbol", default_value = "↵", value_name = "STRING")] /// End-of-line wrapped content symbol (left-aligned). /// /// Symbol added to the end of a line indicating that the content has been wrapped onto the next /// line and continues left-aligned. pub wrap_left_symbol: String, - #[clap(long = "wrap-max-lines", default_value = "2", value_name = "N")] + #[arg(long = "wrap-max-lines", default_value = "2", value_name = "N")] /// How often a line should be wrapped if it does not fit. /// /// Zero means to never wrap. Any content which does not fit after wrapping will be truncated. A /// value of "unlimited" means a line will be wrapped as many times as required. pub wrap_max_lines: String, - #[clap( + #[arg( long = "wrap-right-percent", default_value = "37.0", value_name = "PERCENT" @@ -1034,7 +1033,7 @@ pub struct Opt { /// quantity it will be right-aligned. Otherwise it will be left-aligned. pub wrap_right_percent: String, - #[clap( + #[arg( long = "wrap-right-prefix-symbol", default_value = "…", value_name = "STRING" @@ -1044,14 +1043,14 @@ pub struct Opt { /// Symbol displayed before right-aligned wrapped content. pub wrap_right_prefix_symbol: String, - #[clap(long = "wrap-right-symbol", default_value = "↴", value_name = "STRING")] + #[arg(long = "wrap-right-symbol", default_value = "↴", value_name = "STRING")] /// End-of-line wrapped content symbol (right-aligned). /// /// Symbol added to the end of a line indicating that the content has been wrapped onto the next /// line and continues right-aligned. pub wrap_right_symbol: String, - #[clap( + #[arg( long = "zero-style", default_value = "syntax normal", value_name = "STYLE" @@ -1061,30 +1060,28 @@ pub struct Opt { /// See STYLES section. pub zero_style: String, - #[clap(long = "24-bit-color", value_name = "auto|always|never")] + #[arg(long = "24-bit-color", value_name = "auto|always|never")] /// Deprecated: use --true-color. pub _24_bit_color: Option, - #[clap(value_parser)] /// First file to be compared when delta is being used in diff mode /// /// `delta file_1 file_2` is equivalent to `diff -u file_1 file_2 | delta`. pub minus_file: Option, - #[clap(value_parser)] /// Second file to be compared when delta is being used in diff mode. pub plus_file: Option, - #[clap(skip)] + #[arg(skip)] pub computed: ComputedValues, - #[clap(skip)] + #[arg(skip)] pub git_config: Option, - #[clap(skip)] + #[arg(skip)] pub git_config_entries: HashMap, - #[clap(skip)] + #[arg(skip)] pub env: DeltaEnv, } @@ -1173,14 +1170,17 @@ impl Opt { opt } - pub fn get_argument_and_option_names<'a>() -> HashMap<&'a str, &'a str> { - itertools::chain(Self::command().get_opts(), Self::command().get_arguments()) + pub fn get_argument_and_option_names() -> HashMap { + let command = Self::command(); + command + .get_opts() + .chain(command.get_arguments()) .filter_map(|arg| match (arg.get_id(), arg.get_long()) { - (name, Some(long)) => { - if IGNORED_OPTION_NAMES.contains(name) { + (id, Some(long)) => { + if IGNORED_OPTION_NAMES.contains(long) { None } else { - Some((name, long)) + Some((id.to_string(), long.to_owned())) } } _ => None, diff --git a/src/config.rs b/src/config.rs index 3856f669..e4ac81c4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use std::path::PathBuf; -use clap::ValueSource; +use clap::parser::ValueSource; use regex::Regex; use syntect::highlighting::Style as SyntectStyle; use syntect::highlighting::Theme as SyntaxTheme; diff --git a/src/options/set.rs b/src/options/set.rs index 1f0370b9..27aff042 100644 --- a/src/options/set.rs +++ b/src/options/set.rs @@ -22,9 +22,9 @@ macro_rules! set_options { $opt:expr, $builtin_features:expr, $git_config:expr, $arg_matches:expr, $expected_option_name_map:expr, $check_names:expr) => { let mut option_names = HashSet::new(); $( - let kebab_case_field_name = stringify!($field_ident).replace("_", "-"); - let option_name = $expected_option_name_map[kebab_case_field_name.as_str()]; - if !$crate::config::user_supplied_option(&kebab_case_field_name, $arg_matches) { + let field_name = stringify!($field_ident); + let option_name = &$expected_option_name_map[field_name]; + if !$crate::config::user_supplied_option(&field_name, $arg_matches) { if let Some(value) = $crate::options::get::get_option_value( option_name, &$builtin_features, @@ -35,7 +35,7 @@ macro_rules! set_options { } } if $check_names { - option_names.insert(option_name); + option_names.insert(option_name.as_str()); } )* if $check_names { @@ -44,15 +44,16 @@ macro_rules! set_options { "diff-highlight", // Does not exist as a flag on config "diff-so-fancy", // Does not exist as a flag on config "features", // Processed differently - "help", // automatically added by clap // Set prior to the rest "no-gitconfig", "dark", "light", "syntax-theme", - "version", // automatically added by clap ]); - let expected_option_names: HashSet<_> = $expected_option_name_map.values().cloned().collect(); + let expected_option_names: HashSet<_> = $expected_option_name_map + .values() + .map(String::as_str) + .collect(); if option_names != expected_option_names { $crate::config::delta_unreachable( @@ -88,7 +89,7 @@ pub fn set_options( // --color-only is used for interactive.diffFilter (git add -p) and side-by-side cannot be used // there (does not emit lines in 1-1 correspondence with raw git output). See #274. - if config::user_supplied_option("color-only", arg_matches) { + if config::user_supplied_option("color_only", arg_matches) { builtin_features.remove("side-by-side"); } @@ -101,12 +102,12 @@ pub fn set_options( // HACK: make minus-line styles have syntax-highlighting iff side-by-side. if features.contains(&"side-by-side".to_string()) { let prefix = "normal "; - if !config::user_supplied_option("minus-style", arg_matches) + if !config::user_supplied_option("minus_style", arg_matches) && opt.minus_style.starts_with(prefix) { opt.minus_style = format!("syntax {}", &opt.minus_style[prefix.len()..]); } - if !config::user_supplied_option("minus-emph-style", arg_matches) + if !config::user_supplied_option("minus_emph_style", arg_matches) && opt.minus_emph_style.starts_with(prefix) { opt.minus_emph_style = format!("syntax {}", &opt.minus_emph_style[prefix.len()..]); @@ -115,7 +116,7 @@ pub fn set_options( // Handle options which default to an arbitrary git config value. // TODO: incorporate this logic into the set_options macro. - if !config::user_supplied_option("whitespace-error-style", arg_matches) { + if !config::user_supplied_option("whitespace_error_style", arg_matches) { opt.whitespace_error_style = if let Some(git_config) = git_config { git_config.get::("color.diff.whitespace") } else { @@ -251,7 +252,7 @@ fn set__light__dark__syntax_theme__options( opt: &mut cli::Opt, git_config: &mut Option, arg_matches: &clap::ArgMatches, - option_names: &HashMap<&str, &str>, + option_names: &HashMap, ) { let validate_light_and_dark = |opt: &cli::Opt| { if opt.light && opt.dark { -- cgit v1.2.3