diff options
| author | Dan Davison <dandavison7@gmail.com> | 2022-01-15 20:59:57 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-15 20:59:57 -0500 |
| commit | f498544dfd0ffe7d1a3edbfef65a5067ad50091d (patch) | |
| tree | 9f927d7c06093f60bf36a6c0abd781c41f00e39e /src/cli.rs | |
| parent | a2038166d64f5cef5c5436590560d08467ca596d (diff) | |
structopt to clap (#889)
Replace structopt with clap
Fixes #888
* Drop tests of deprecated options
They were failing
Diffstat (limited to 'src/cli.rs')
| -rw-r--r-- | src/cli.rs | 840 |
1 files changed, 477 insertions, 363 deletions
@@ -2,26 +2,25 @@ use std::collections::{HashMap, HashSet}; use std::ffi::OsString; use std::path::PathBuf; +use clap::{AppSettings, ColorChoice, FromArgMatches, IntoApp, Parser}; use lazy_static::lazy_static; -use structopt::clap::AppSettings::{ColorAlways, ColoredHelp, DeriveDisplayOrder}; -use structopt::{clap, StructOpt}; use syntect::highlighting::Theme as SyntaxTheme; use syntect::parsing::SyntaxSet; +use crate::config::delta_unreachable; use crate::git_config::{GitConfig, GitConfigEntry}; use crate::options; use crate::utils::bat::assets::HighlightingAssets; use crate::utils::bat::output::PagingMode; -// No Default trait as this ignores `default_value = ..` -#[derive(StructOpt)] -#[structopt( +#[derive(Parser)] +#[clap( name = "delta", about = "A viewer for git and diff output", - setting(ColorAlways), - setting(ColoredHelp), - setting(DeriveDisplayOrder), - after_help = "\ + version, + color = ColorChoice::Always, + setting(AppSettings::DeriveDisplayOrder), + after_long_help = "\ GIT CONFIG ---------- @@ -204,632 +203,746 @@ https://github.com/dandavison/delta/issues. " )] pub struct Opt { - /// Use default colors appropriate for a light terminal background. For more control, see the - /// style options and --syntax-theme. - #[structopt(long = "light")] + #[clap(long = "light")] + /// Use default colors appropriate for a light terminal background. + /// + /// For more control, see the style options and --syntax-theme. pub light: bool, - /// Use default colors appropriate for a dark terminal background. For more control, see the - /// style options and --syntax-theme. - #[structopt(long = "dark")] + #[clap(long = "dark")] + /// Use default colors appropriate for a dark terminal background. + /// + /// For more control, see the style options and --syntax-theme. pub dark: bool, - /// Display line numbers next to the diff. See LINE NUMBERS section. - #[structopt(short = "n", long = "line-numbers")] + #[clap(short = 'n', long = "line-numbers")] + /// Display line numbers next to the diff. + /// + /// See LINE NUMBERS section. pub line_numbers: bool, - /// Display a side-by-side diff view instead of the traditional view. - #[structopt(short = "s", long = "side-by-side")] + #[clap(short = 's', long = "side-by-side")] + /// Display diffs in side-by-side layout. pub side_by_side: bool, - #[structopt(long = "diff-highlight")] - /// Emulate diff-highlight (https://github.com/git/git/tree/master/contrib/diff-highlight) + #[clap(long = "diff-highlight")] + /// Emulate diff-highlight. + /// + /// (https://github.com/git/git/tree/master/contrib/diff-highlight) pub diff_highlight: bool, - #[structopt(long = "diff-so-fancy")] - /// Emulate diff-so-fancy (https://github.com/so-fancy/diff-so-fancy) + #[clap(long = "diff-so-fancy")] + /// Emulate diff-so-fancy. + /// + /// (https://github.com/so-fancy/diff-so-fancy) pub diff_so_fancy: bool, - #[structopt(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. + #[clap(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, - #[structopt(long = "relative-paths")] - /// Output all file paths relative to the current directory so that they - /// resolve correctly when clicked on or used in shell commands. + #[clap(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, - #[structopt(long = "hyperlinks")] - /// Render commit hashes, file names, and line numbers as hyperlinks, - /// according to the hyperlink spec for terminal emulators: - /// https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda. By - /// default, file names and line numbers link to the local file using a file - /// URL, whereas commit hashes link to the commit in GitHub, if the remote - /// repository is hosted by GitHub. See --hyperlinks-file-link-format for - /// full control over the file URLs emitted. Hyperlinks are supported by - /// several common terminal emulators. To make them work, you must use less - /// version >= 581 with the -R flag (or use -r with older less versions, but - /// this will break e.g. --navigate). If you use tmux, then you will also - /// need a patched fork of tmux (see https://github.com/dandavison/tmux). + #[clap(long = "hyperlinks")] + /// Render commit hashes, file names, and line numbers as hyperlinks. + /// + /// Following the hyperlink spec for terminal emulators: + /// https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda. By default, file names + /// and line numbers link to the local file using a file URL, whereas commit hashes link to the + /// commit in GitHub, if the remote repository is hosted by GitHub. See + /// --hyperlinks-file-link-format for full control over the file URLs emitted. Hyperlinks are + /// supported by several common terminal emulators. To make them work, you must use less version + /// >= 581 with the -R flag (or use -r with older less versions, but this will break e.g. + /// --navigate). If you use tmux, then you will also need a patched fork of tmux (see + /// https://github.com/dandavison/tmux). pub hyperlinks: bool, - #[structopt(long = "keep-plus-minus-markers")] - /// Prefix added/removed lines with a +/- character, exactly as git does. By default, delta - /// does not emit any prefix, so code can be copied directly from delta's output. + #[clap(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, - /// Display the active values for all Delta options. Style options are displayed with - /// foreground and background colors. This can be used to experiment with colors by combining - /// this option with other options such as --minus-style, --zero-style, --plus-style, --light, - /// --dark, etc. - #[structopt(long = "show-config")] + #[clap(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 + /// experiment with colors by combining this option with other options such as --minus-style, + /// --zero-style, --plus-style, --light, --dark, etc. pub show_config: bool, + #[clap(long = "list-languages")] /// List supported languages and associated file extensions. - #[structopt(long = "list-languages")] pub list_languages: bool, + #[clap(long = "list-syntax-themes")] /// List available syntax-highlighting color themes. - #[structopt(long = "list-syntax-themes")] pub list_syntax_themes: bool, - /// Show all available syntax-highlighting themes, each with an example of highlighted diff output. + #[clap(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`. - #[structopt(long = "show-syntax-themes")] pub show_syntax_themes: bool, - /// Show available delta themes, each with an example of highlighted diff - /// output. A delta theme is a delta named feature (see --features) that - /// sets either `light` or `dark`. See - /// https://github.com/dandavison/delta#custom-color-themes. If diff output - /// is supplied on standard input then this will be used for the demo. For - /// example: `git show | delta --show-themes`. By default shows dark or - /// light themes only, according to whether delta is in dark or light mode - /// (as set by the user or inferred from BAT_THEME). To control the themes - /// shown, use --dark or --light, or both, on the command line together with - /// this option. - #[structopt(long = "show-themes")] + #[clap(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`. + /// See https://github.com/dandavison/delta#custom-color-themes. If diff output is supplied on + /// standard input then this will be used for the demo. For example: `git show | delta + /// --show-themes`. By default shows dark or light themes only, according to whether delta is in + /// dark or light mode (as set by the user or inferred from BAT_THEME). To control the themes + /// shown, use --dark or --light, or both, on the command line together with this option. pub show_themes: bool, - /// Show available named colors. In addition to named colors, arbitrary - /// colors can be specified using RGB hex codes. See COLORS section. - #[structopt(long = "show-colors")] + #[clap(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, - /// Parse ANSI color escape sequences in input and display them as git style - /// strings. Example usage: git show --color=always | delta --parse-ansi + #[clap(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. - #[structopt(long = "parse-ansi")] pub parse_ansi: bool, - #[structopt(long = "no-gitconfig")] - /// Do not take any settings from git config. See GIT CONFIG section. + #[clap(long = "no-gitconfig")] + /// Do not read any settings from git config. + /// + /// See GIT CONFIG section. pub no_gitconfig: bool, - #[structopt(long = "raw")] - /// Do not alter the input in any way. This is mainly intended for testing delta. + #[clap(long = "raw")] + /// Do not alter the input in any way. + /// + /// This is mainly intended for testing delta. pub raw: bool, - #[structopt(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. + #[clap(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, //////////////////////////////////////////////////////////////////////////////////////////// - #[structopt(long = "features")] - /// Name of delta features to use (space-separated). A feature is a named collection of delta - /// options in ~/.gitconfig. See FEATURES section. The environment variable DELTA_FEATURES can - /// be set to a space-separated list of feature names. If this is preceded with a space, the - /// features from the environment variable will be added to those specified in git config. E.g. - /// DELTA_FEATURES=+side-by-side can be used to activate side-by-side temporarily. + #[clap(long = "features")] + /// Names of delta features to activate (space-separated). + /// + /// A feature is a named collection of delta options in ~/.gitconfig. See FEATURES section. The + /// environment variable DELTA_FEATURES can be set to a space-separated list of feature names. + /// If this is preceded with a space, the features from the environment variable will be added + /// to those specified in git config. E.g. DELTA_FEATURES=+side-by-side can be used to activate + /// side-by-side temporarily. pub features: Option<String>, - #[structopt(long = "syntax-theme")] - /// The code syntax-highlighting theme to use. Use --show-syntax-themes to demo available - /// themes. Defaults to the value of the BAT_THEME environment variable, if that contains a - /// valid theme name. --syntax-theme=none disables all syntax highlighting. + #[clap(long = "syntax-theme")] + /// The syntax-highlighting theme to use. + /// + /// Use --show-syntax-themes to demo available themes. Defaults to the value of the BAT_THEME + /// environment variable, if that contains a valid theme name. --syntax-theme=none disables all + /// syntax highlighting. pub syntax_theme: Option<String>, - #[structopt(long = "minus-style", default_value = "normal auto")] - /// Style (foreground, background, attributes) for removed lines. See STYLES section. + #[clap(long = "minus-style", default_value = "normal auto")] + /// Style string for removed lines. + /// + /// See STYLES section. pub minus_style: String, - #[structopt(long = "zero-style", default_value = "syntax normal")] - /// Style (foreground, background, attributes) for unchanged lines. See STYLES section. + #[clap(long = "zero-style", default_value = "syntax normal")] + /// Style string for unchanged lines. + /// + /// See STYLES section. pub zero_style: String, - #[structopt(long = "plus-style", default_value = "syntax auto")] - /// Style (foreground, background, attributes) for added lines. See STYLES section. + #[clap(long = "plus-style", default_value = "syntax auto")] + /// Style string for added lines. + /// + /// See STYLES section. pub plus_style: String, - #[structopt(long = "minus-emph-style", default_value = "normal auto")] - /// Style (foreground, background, attributes) for emphasized sections of removed lines. See - /// STYLES section. + #[clap(long = "minus-emph-style", default_value = "normal auto")] + /// Style string for emphasized sections of removed lines. + /// + /// See STYLES section. pub minus_emph_style: String, - #[structopt(long = "minus-non-emph-style", default_value = "minus-style")] - /// Style (foreground, background, attributes) for non-emphasized sections of removed lines - /// that have an emphasized section. See STYLES section. + #[clap(long = "minus-non-emph-style", default_value = "minus-style")] + /// Style string for non-emphasized sections of removed lines that have an emphasized section. + /// + /// See STYLES section. pub minus_non_emph_style: String, - #[structopt(long = "plus-emph-style", default_value = "syntax auto")] - /// Style (foreground, background, attributes) for emphasized sections of added lines. See - /// STYLES section. + #[clap(long = "plus-emph-style", default_value = "syntax auto")] + /// Style string for emphasized sections of added lines. + /// + /// See STYLES section. pub plus_emph_style: String, - #[structopt(long = "plus-non-emph-style", default_value = "plus-style")] - /// Style (foreground, background, attributes) for non-emphasized sections of added lines that - /// have an emphasized section. See STYLES section. + #[clap(long = "plus-non-emph-style", default_value = "plus-style")] + /// Style string for non-emphasized sections of added lines that have an emphasized section. + /// + /// See STYLES section. pub plus_non_emph_style: String, - #[structopt(long = "commit-style", default_value = "raw")] - /// Style (foreground, background, attributes) for the commit hash line. See STYLES section. - /// The style 'omit' can be used to remove the commit hash line from the output. + #[clap(long = "commit-style", default_value = "raw")] + /// 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, - #[structopt(long = "commit-decoration-style", default_value = "")] - /// Style (foreground, background, attributes) for the commit hash decoration. See STYLES - /// section. The style string should contain one of the special attributes 'box', 'ul' - /// (underline), 'ol' (overline), or the combination 'ul ol'. + #[clap(long = "commit-decoration-style", default_value = "")] + /// Style string for the commit hash decoration. + /// + /// See STYLES section. The style string should contain one of the special attributes 'box', + /// 'ul' (underline), 'ol' (overline), or the combination 'ul ol'. pub commit_decoration_style: String, - /// The regular expression used to identify the commit line when parsing git output. - #[structopt(long = "commit-regex", default_value = r"^commit ")] + #[clap(long = "commit-regex", default_value = r"^commit ")] + /// Regular expression used to identify the commit line when parsing git output. pub commit_regex: String, - #[structopt(long = "file-style", default_value = "blue")] - /// Style (foreground, background, attributes) for the file section. See STYLES section. The - /// style 'omit' can be used to remove the file section from the output. + #[clap(long = "file-style", default_value = "blue")] + /// 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-decoration-style", default_value = "blue ul")] - /// Style (foreground, background, attributes) for the file decoration. See STYLES section. The - /// style string should contain one of the special attributes 'box', 'ul' (underline), 'ol' - /// (overline), or the combination 'ul ol'. + #[clap(long = "file-decoration-style", default_value = "blue ul")] + /// Style string for the file decoration. + /// + /// See STYLES section. The style string should contain one of the special attributes 'box', + /// 'ul' (underline), 'ol' (overline), or the combination 'ul ol'. pub file_decoration_style: String, #[structopt(long = "file-transformation")] - /// A sed-style command specifying how file paths should be transformed for display. + /// A sed-style command transforming file paths for display. pub file_regex_replacement: Option<String>, - /// Format string for commit hyperlinks (requires --hyperlinks). The - /// placeholder "{commit}" will be replaced by the commit hash. For example: + #[clap(long = "hyperlinks-commit-link-format")] + /// 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}/' - #[structopt(long = "hyperlinks-commit-link-format")] pub hyperlinks_commit_link_format: Option<String>, - /// Format string for file hyperlinks (requires --hyperlinks). The - /// placeholders "{path}" and "{line}" will be replaced by the absolute file - /// path and the line number, respectively. The default value of this option - /// creates hyperlinks using standard file URLs; your operating system - /// should open these in the application registered for that file type. - /// However, these do not make use of the line number. In order for the link - /// to open the file at the correct line number, you could use a custom URL - /// format such as "file-line://{path}:{line}" and register an application - /// to handle the custom "file-line" URL scheme by opening the file in your - /// editor/IDE at the indicated line number. See + #[clap(long = "hyperlinks-file-link-format", default_value = "file://{path}")] + /// Format string for file hyperlinks (requires --hyperlinks). + /// + /// The placeholders "{path}" and "{line}" will be replaced by the absolute file path and the + /// line number, respectively. The default value of this option creates hyperlinks using + /// standard file URLs; your operating system should open these in the application registered + /// for that file type. However, these do not make use of the line number. In order for the link + /// to open the file at the correct line number, you could use a custom URL format such as + /// "file-line://{path}:{line}" and register an application to handle the custom "file-line" URL + /// scheme by opening the file in your editor/IDE at the indicated line number. See /// https://github.com/dandavison/open-in-editor for an example. - #[structopt(long = "hyperlinks-file-link-format", default_value = "file://{path}")] pub hyperlinks_file_link_format: String, - #[structopt(long = "hunk-header-style", default_value = "line-number syntax")] - /// Style (foreground, background, attributes) for the hunk-header. See STYLES section. Special - /// attributes 'file' and 'line-number' can be used to include the file path, and number of - /// first hunk line, in the hunk header. The style 'omit' can be used to remove the hunk header - /// section from the output. + #[clap(long = "hunk-header-style", default_value = "line-number syntax")] + /// Style string for the hunk-header. + /// + /// See STYLES section. Special attributes 'file' and 'line-number' can be used to include the + /// file path, and number of first hunk line, in the hunk header. The style 'omit' can be used + /// to remove the hunk header section from the output. pub hunk_header_style: String, - #[structopt(long = "hunk-header-file-style", default_value = "blue")] - /// Style (foreground, background, attributes) for the file path part of the hunk-header. See - /// STYLES section. The file path will only be displayed if hunk-header-style contains the + #[clap(long = "hunk-header-file-style", default_value = "blue")] + /// Style string for the file path part of the hunk-header. + /// + /// See STYLES section. The file path will only be displayed if hunk-header-style contains the /// 'file' special attribute. pub hunk_header_file_style: String, - #[structopt(long = "hunk-header-line-number-style", default_value = "blue")] - /// Style (foreground, background, attributes) for the line number part of the hunk-header. See - /// STYLES section. The line number will only be displayed if hunk-header-style contains the + #[clap(long = "hunk-header-line-number-style", default_value = "blue")] + /// Style string for the line number part of the hunk-header. + /// + /// See STYLES section. The line number will only be displayed if hunk-header-style contains the /// 'line-number' special attribute. pub hunk_header_line_number_style: String, - #[structopt(long = "hunk-header-decoration-style", default_value = "blue box")] - /// Style (foreground, background, attributes) for the hunk-header decoration. See STYLES - /// section. The style string should contain one of the special attributes 'box', 'ul' - /// (underline), 'ol' (overline), or the combination 'ul ol'. + #[clap(long = "hunk-header-decoration-style", default_value = "blue box")] + /// Style string for the hunk-header decoration. + /// + /// See STYLES section. The style string should contain one of the special attributes 'box', + /// 'ul' (underline), 'ol' (overline), or the combination 'ul ol'. pub hunk_header_decoration_style: String, - #[structopt(long = "merge-conflict-begin-symbol", default_value = "▼")] - /// A string that is repeated to form the line marking the beginning of a merge conflict region. + #[clap(long = "merge-conflict-begin-symbol", default_value = "▼")] + /// String marking the beginning of a merge conflict region. + /// + /// The string will be repeated until it reaches the required length. pub merge_conflict_begin_symbol: String, - #[structopt(long = "merge-conflict-end-symbol", default_value = "▲")] - /// A string that is repeated to form the line marking the end of a merge conflict region. + #[clap(long = "merge-conflict-end-symbol", default_value = "▲")] + /// String marking the end of a merge conflict region. + /// + /// The string will be repeated until it reaches the required length. pub merge_conflict_end_symbol: String, - #[structopt( + #[clap( long = "merge-conflict-ours-diff-header-style", default_value = "normal" )] - /// Style (foreground, background, attributes) for the header above the diff between the - /// ancestral commit and 'our' branch. See STYLES section. + /// Style string for the header above the 'ours' branch merge conflict diff. + /// + /// See STYLES section. pub merge_conflict_ours_diff_header_style: String, - #[structopt( + #[clap( long = "merge-conflict-ours-diff-header-decoration-style", default_value = "box" )] - /// Style (foreground, background, attributes) for the decoration of the header above the diff - /// between the ancestral commit and 'our' branch. See STYLES section. The style string should - /// contain one of the special attributes 'box', 'ul' (underline), 'ol' (overline), or the - /// combination 'ul ol'. + /// Style string for the decoration of the header above the 'ours' merge conflict diff. + /// + /// This styles the decoration of the header above the diff between the ancestral commit and the + /// 'ours' branch. See STYLES section. The style string should contain one of the special + /// attributes 'box', 'ul' (underline), 'ol' (overline), or the combination 'ul ol'. pub merge_conflict_ours_diff_header_decoration_style: String, - #[structopt( + #[clap( long = "merge-conflict-theirs-diff-header-style", default_value = "normal" )] - /// Style (foreground, background, attributes) for the header above the diff between the - /// ancestral commit and 'their' branch. See STYLES section. + /// Style string for the header above the 'theirs' branch merge conflict diff. + /// + /// This styles the header above the diff between the ancestral commit and 'their' branch. See + /// STYLES section. pub merge_conflict_theirs_diff_header_style: String, - #[structopt( + #[clap( long = "merge-conflict-theirs-diff-header-decoration-style", default_value = "box" )] - /// Style (foreground, background, attributes) for the decoration of the header above the diff - /// between the ancestral commit and 'their' branch. See STYLES section. The style string should - /// contain one of the special attributes 'box', 'ul' (underline), 'ol' (overline), or the - /// combination 'ul ol'. + /// Style string for the decoration of the header above the 'theirs' merge conflict diff. + /// + /// This styles the decoration of the header above the diff between the ancestral commit and + /// 'their' branch. See STYLES section. The style string should contain one of the special + /// attributes 'box', 'ul' (underline), 'ol' (overline), or the combination 'ul ol'. pub merge_conflict_theirs_diff_header_decoration_style: String, - #[structopt(long = "map-styles")] - /// A string specifying a mapping styles encountered in raw input to desired - /// output styles. An example is - /// --map-styles='bold purple => red "#eeeeee", bold cyan => syntax "#eeeeee"' + #[clap(long = "map-styles")] + /// 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<String>, - /// Format string for git blame commit metadata. Available placeholders are - /// "{timestamp}", "{author}", and "{commit}". - #[structopt( + #[clap( long = "blame-format", default_value = "{timestamp:<15} {author:<15.14} {commit:<8}" )] + /// Format string for git blame commit metadata. + /// + /// Available placeholders are "{timestamp}", "{author}", and "{commit}". pub blame_format: String, - /// Separator between the commit metadata and code sections of a line of git blame output. - #[structopt(long = "blame-separator", default_value = "│")] + #[clap(long = "blame-separator", default_value = "│")] + /// Separator between the commit metadata and code sections of a git blame line. pub blame_separator: String, - #[structopt(long = "blame-separator-style")] - /// Style (foreground, background, attributes) for the separator between the commit metadata and - /// code sections of a line of `git blame` output. + #[clap(long = "blame-separator-style")] + /// Style string for the separator between the commit metadata and code sections of a git blame line. pub blame_separator_style: Option<String>, - #[structopt(long = "blame-code-style")] - /// Style (foreground, background, attributes) for the code section of a line of `git blame` - /// output. By default the code will be syntax-highlighted with the same background color as the - /// blame format section of the line (the background color is determined by blame-palette). E.g. + #[clap(long = "blame-code-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 + /// format section of the line (the background color is determined by blame-palette). E.g. /// setting this option to 'syntax' will syntax-highlight the code with no background color. pub blame_code_style: Option<String>, + #[clap(long = "blame-palette")] /// 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. - #[structopt(long = "blame-palette")] + /// + /// Lines added by the same commit are painted with the same color; colors are recycled as + /// needed. pub blame_palette: Option<String>, - /// Format of `git blame` timestamp in raw git output received by delta. - #[structopt( + #[clap( long = "blame-timestamp-format", default_value = "%Y-%m-%d %H:%M:%S %z" )] + /// Format of `git blame` timestamp in raw git output received by delta. pub blame_timestamp_format: String, - #[structopt(long = "grep-match-line-style")] - /// Style (foreground, background, attributes) for matching lines of code in - /// grep output. See STYLES section. Defaults to plus-style. + #[clap(long = "grep-match-line-style")] + /// Style string for matching lines of grep output. + /// + /// See STYLES section. Defaults to plus-style. pub grep_match_line_style: Option<String>, - #[structopt(long = "grep-match-word-style")] - /// Style (foreground, background, attributes) for the specific matching - /// substrings within a matching line of code in grep output. See STYLES - /// section. Defaults to plus-style. + #[clap(long = "grep-match-word-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<String>, - #[structopt(long = "grep-context-line-style")] - /// Style (foreground, background, attributes) for non-matching lines of - /// code in grep output. See STYLES section. Defaults to zero-style. + #[clap(long = "grep-context-line-style")] + /// Style string for non-matching lines of grep output. + /// + /// See STYLES section. Defaults to zero-style. pub grep_context_line_style: Option<String>, - #[structopt(long = "grep-file-style")] - /// Style (foreground, background, attributes) for file paths in grep - /// output. See STYLES section. Defaults to hunk-header-file-path-style. + #[clap(long = "grep-file-style")] + /// Style string for file paths in grep output. + /// + /// See STYLES section. Defaults to hunk-header-file-path-style. pub grep_file_style: Option<String>, - #[structopt(long = "grep-line-number-style")] - /// Style (foreground, background, attributes) for line numbers in grep - /// output. See STYLES section. Defaults to hunk-header-line-number-style. + #[clap(long = "grep-line-number-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<String>, - #[structopt(long = "grep-separator-symbol", default_value = ":")] - /// Symbol used in grep output to separate file path (and line number) from - /// the line of file contents. Defaults to ":" for both match and context - /// lines, since many terminal emulators recognize constructs like - /// "/path/to/file:7:". However, standard grep output uses "-" for context + #[clap(long = "grep-separator-symbol", default_value = ":")] + /// Separator symbol printed after the file path and line number in grep output. + /// + /// Defaults to ":" for both match and context lines, since many terminal emulators recognize + /// constructs like "/path/to/file:7:". However, standard grep output uses "-" for context /// lines: set this option to "keep" to keep the original separator symbols. pub grep_separator_symbol: String, - /// Default language used for syntax highlighting when this cannot be - /// inferred from a filename. It will typically make sense to set this in - /// per-repository git config (.git/config) - #[structopt(long = "default-language")] + #[clap(long = "default-language")] + /// 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<String>, - #[structopt(long = "inline-hint-style", default_value = "blue")] - /// Style (foreground, background, attributes) for content added by delta to - /// the original diff such as special characters to highlight tabs, and the - /// symbols used to indicate wrapped lines. See STYLES section. + #[clap(long = "inline-hint-style", default_value = "blue")] + /// Style string for short inline hint text. + /// + /// This styles certain content added by delta to the original diff such as special characters + /// to highlight tabs, and the symbols used to indicate wrapped lines. See STYLES section. pub inline_hint_style: String, + #[clap(long = "word-diff-regex", default_value = r"\w+")] + /// 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 /// algorithm. For less fine-grained matching than the default try --word-diff-regex="\S+" /// --max-line-distance=1.0 (this is more similar to `git --word-diff`). - #[structopt(long = "word-diff-regex", default_value = r"\w+")] pub tokenization_regex: String, - /// The maximum distance between two lines for them to be inferred to be homologous. Homologous - /// line pairs are highlighted according to the deletion and insertion operations transforming - /// one into the other. - #[structopt(long = "max-line-distance", default_value = "0.6")] + #[clap(long = "max-line-distance", default_value = "0.6")] + /// 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 + /// to be homologous. Homologous line pairs are highlighted according to the deletion and + /// insertion operations transforming one into the other. pub max_line_distance: f64, - /// Style (foreground, background, attributes) for line numbers in the old (minus) version of - /// the file. See STYLES and LINE NUMBERS sections. - #[structopt(long = "line-numbers-minus-style", default_value = "auto")] + #[clap(long = "line-numbers-minus-style", default_value = "auto")] + /// Style string for line numbers in the old (minus) version of the file. + /// + /// See STYLES and LINE NUMBERS sections. pub line_numbers_minus_style: String, - /// Style (foreground, background, attributes) for line numbers in unchanged (zero) lines. See - /// STYLES and LINE NUMBERS sections. - #[structopt(long = "line-numbers-zero-style", default_value = "auto")] + #[clap(long = "line-numbers-zero-style", default_value = "auto")] + /// Style string for line numbers in unchanged (zero) lines. + /// + /// See STYLES and LINE NUMBERS sections. pub line_numbers_zero_style: String, - /// Style (foreground, background, attributes) for line numbers in the new (plus) version of - /// the file. See STYLES and LINE NUMBERS sections. - #[structopt(long = "line-numbers-plus-style", default_value = "auto")] + #[clap(long = "line-numbers-plus-style", default_value = "auto")] + /// Style string for line numbers in the new (plus) version of the file. + /// + /// See STYLES and LINE NUMBERS sections. pub line_numbers_plus_style: String, - /// Format string for the left column of line numbers. A typical value would be "{nm:^4}⋮" - /// which means to display the line numbers of the minus file (old version), center-aligned, - /// padded to a width of 4 characters, followed by a dividing character. See the LINE NUMBERS - /// section. - #[structopt(long = "line-numbers-left-format", default_value = "{nm:^4}⋮")] + #[clap(long = "line-numbers-left-format", default_value = "{nm:^4}⋮")] + /// Format string for the left column of line numbers. + /// + /// A typical value would be "{nm:^4}⋮" which means to display the line numbers of the minus + /// file (old version), center-aligned, padded to a width of 4 characters, followed by a + /// dividing character. See the LINE NUMBERS section. pub line_numbers_left_format: String, - /// Format string for the right column of line numbers. A typical value would be "{np:^4}│ " - /// which means to display the line numbers of the plus file (new version), center-aligned, - /// padded to a width of 4 characters, followed by a dividing character, and a space. See the - /// LINE NUMBERS section. - #[structopt(long = "line-numbers-right-format", default_value = "{np:^4}│")] + #[clap(long = "line-numbers-right-format", default_value = "{np:^4}│")] + /// Format string for the right column of line numbers. + /// + /// A typical value would be "{np:^4}│ " which means to display the line numbers of the plus + /// file (new version), center-aligned, padded to a width of 4 characters, followed by a + /// dividing character, and a space. See the LINE NUMBERS section. pub line_numbers_right_format: String, - /// Style (foreground, background, attributes) for the left column of line numbers. See STYLES - /// and LINE NUMBERS sections. - #[structopt(long = "line-numbers-left-style", default_value = "auto")] + #[clap(long = "line-numbers-left-style", default_value = "auto")] + /// Style string for the left column of line numbers. + /// + /// See STYLES and LINE NUMBERS sections. pub line_numbers_left_style: String, - /// Style (foreground, background, attributes) for the right column of line numbers. See STYLES - /// and LINE NUMBERS sections. - #[structopt(long = "line-numbers-right-style", default_value = "auto")] + #[clap(long = "line-numbers-right-style", default_value = "auto")] + /// Style string for the right column of line numbers. + /// + /// See STYLES and LINE NUMBERS sections. pub line_numbers_right_style: String, - /// How often a line should be wrapped if it does not fit. Zero means to never wrap. Any content - /// which does not fit will be truncated. A value of "unlimited" means a line will be wrapped - /// as many times as required. - #[structopt(long = "wrap-max-lines", default_value = "2")] + #[clap(long = "wrap-max-lines", default_value = "2")] + /// How often a line should be wrapped if it does not fit. + /// + /// Zero means to never wrap. Any content which does not fit will be truncated. A value of + /// "unlimited" means a line will be wrapped as many times as required. pub wrap_max_lines: String, - /// Symbol added to the end of a line indicating that the content has been wrapped - /// onto the next line and continues left-aligned. - #[structopt(long = "wrap-left-symbol", default_value = "↵")] + #[clap(long = "wrap-left-symbol", default_value = "↵")] + /// 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, - /// Symbol added to the end of a line indicating that the content has been wrapped - /// onto the next line and continues right-aligned. - #[structopt(long = "wrap-right-symbol", default_value = "↴")] + #[clap(long = "wrap-right-symbol", default_value = "↴")] + /// 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, - /// Threshold for right-aligning wrapped content. If the length of the remaining wrapped - /// content, as a percentage of width, is less than this quantity it will be right-aligned. - /// Otherwise it will be left-aligned. - #[structopt(long = "wrap-right-percent", default_value = "37.0")] + #[clap(long = "wrap-right-percent", default_value = "37.0")] + /// Threshold for right-aligning wrapped content. + /// + /// If the length of the remaining wrapped content, as a percentage of width, is less than this + /// quantity it will be right-aligned. Otherwise it will be left-aligned. pub wrap_right_percent: String, + #[clap(long = "wrap-right-prefix-symbol", default_value = "…")] + /// Pre-wrapped content symbol (right-aligned). + /// /// Symbol displayed in front of right-aligned wrapped content. - #[structopt(long = "wrap-right-prefix-symbol", default_value = "…")] pub wrap_right_prefix_symbol: String, - #[structopt(long = "navigate-regex")] - /// A regexp to use in the less pager when navigating (auto-generated when unspecified) + #[clap(long = "navigate-regex")] + /// Regular expression defining navigation stop points. pub navigate_regex: Option<String>, - #[structopt(long = "file-modified-label", default_value = "")] + #[clap(long = "file-modified-label", default_value = "")] /// Text to display in front of a modified file path. + /// + /// Used in the default value of navigate-regex. pub file_modified_label: String, - #[structopt(long = "file-removed-label", default_value = "removed:")] + #[clap(long = "file-removed-label", default_value = "removed:")] /// Text to display in front of a removed file path. + /// + /// Used in the default value of navigate-regex. pub file_removed_label: String, - #[structopt(long = "file-added-label", default_value = "added:")] - /// Text to display in front of a added file path. + #[clap(long = "file-added-label", default_value = "added:")] + /// Text to display in front of an added file path. + /// + /// Used in the default value of navigate-regex. pub file_added_label: String, - #[structopt(long = "file-copied-label", default_value = "copied:")] + #[clap(long = "file-copied-label", default_value = "copied:")] /// Text to display in front of a copied file path. pub file_copied_label: String, - #[structopt(long = "file-renamed-label", default_value = "renamed:")] + #[clap(long = "file-renamed-label", default_value = "renamed:")] /// Text to display in front of a renamed file path. + /// + /// Used in the default value of navigate-regex. pub file_renamed_label: String, - #[structopt(long = "right-arrow", default_value = "⟶ ")] - /// Text to display with a changed value such as a diff heading, a rename, or a chmod. + #[clap(long = "right-arrow", default_value = "⟶ ")] + /// Text to display with a changed file path. + /// + /// For example, a unified diff heading, a rename, or a chmod. pub right_arrow: String, - #[structopt(long = "hunk-label", default_value = "")] + #[clap(long = "hunk-label", default_value = "")] /// Text to display in front of a hunk header. + /// + /// Used in the default value of navigate-regex. pub hunk_label: String, - #[structopt(long = "max-line-length", default_value = "512")] - /// Truncate lines longer than this. To prevent any truncation, set to zero. Note that - /// delta will be slow on very long lines (e.g. minified .js) if truncation is disabled. - /// When wrapping lines it is automatically set to fit at least all visible characters. + #[clap(long = "max-line-length", default_value = "512")] + /// Truncate lines longer than this. + /// + /// To prevent any truncation, set to zero. Note that delta will be slow on very long lines + /// (e.g. minified .js) if truncation is disabled. When wrapping lines it is automatically set + /// to fit at least all visible characters. pub max_line_length: usize, - /// How to extend the background color to the end of the line in side-by-side mode. Can - /// be ansi (default) or spaces (default if output is not to a terminal). Has no effect - /// if --width=variable is given. - #[structopt(long = "line-fill-method")] + #[clap(long = "line-fill-method")] + /// 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 + /// (default) or spaces (default if output is not to a terminal). Has no effect if + /// --width=variable is given. pub line_fill_method: Option<String>, - /// The width of underline/overline decorations. Examples: "72" (exactly 72 characters), - /// "-2" (auto-detected terminal width minus 2). An expression such as "74-2" is also valid - /// (equivalent to 72 but may be useful if the caller has a variable holding the value "74"). - /// Use --width=variable to extend decorations and background colors to the end of the text - /// only. Otherwise background colors extend to the full terminal width. - #[structopt(short = "w", long = "width")] + #[clap(short = 'w', long = "width")] + /// The width of underline/overline decorations. + /// + /// Examples: "72" (exactly 72 characters), "-2" (auto-detected terminal width minus 2). An + /// expression such as "74-2" is also valid (equivalent to 72 but may be useful if the caller + /// has a variable holding the value "74"). Use --width=variable to extend decorations and + /// background colors to the end of the text only. Otherwise background colors extend to the + /// full terminal width. pub width: Option<String>, - /// 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. - #[structopt(long = "diff-stat-align-width", default_value = "48")] + #[clap(long = "diff-stat-align-width", default_value = "48")] + /// 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, - /// 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 calculate line widths assuming tabs - /// occupy one character's width on the screen: if your terminal renders tabs as more than than - /// one character wide then delta's output will look incorrect. - #[structopt(long = "tabs", default_value = "4")] + #[clap(long = "tabs", default_value = "4")] + /// 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 + /// calculate line widths assuming tabs occupy one character's width on the screen: if your + /// terminal renders tabs as more than than one character wide then delta's output will look + /// incorrect. pub tab_width: usize, - /// Whether to emit 24-bit ("true color") RGB color codes. Options are auto, always, and never. - /// "auto" means that delta will emit 24-bit color codes if the environment variable COLORTERM - /// has the value "truecolor" or "24bit". If your terminal application (the application you use - /// to enter commands at a shell prompt) supports 24 bit colors, then it probably already sets - /// this environment variable, in which case you don't need to do anything. - #[structopt(long = "true-color", default_value = "auto")] + #[clap(long = "true-color", default_value = "auto")] + /// Whether to emit 24-bit ("true color") RGB color codes. + /// + /// Options are auto, always, and never. "auto" means that delta will emit 24-bit color codes if + /// the environment variable COLORTERM has the value "truecolor" or "24bit". If your terminal + /// application (the application you use to enter commands at a shell prompt) supports 24 bit + /// colors, then it probably already sets this environment variable, in which case you don't + /// need to do anything. pub true_color: String, + #[clap(long = "24-bit-color")] /// Deprecated: use --true-color. - #[structopt(long = "24-bit-color")] pub _24_bit_color: Option<String>, + #[clap(long = "inspect-raw-lines", default_value = "true")] + /// Kill-switch for --color-moved support. + /// /// Whether to examine ANSI color escape sequences in raw lines received from Git and handle /// lines colored in certain ways specially. This is on by default: it is how Delta supports /// Git's --color-moved feature. Set this to "false" to disable this behavior. - #[structopt(long = "inspect-raw-lines", default_value = "true")] pub inspect_raw_lines: String, - #[structopt(long)] - /// Which pager to use. The default pager is `less`. You can also change pager - /// by setting the environment variables DELTA_PAGER, BAT_PAGER, or PAGER - /// (and that is their order of priority). This option overrides all environment - /// variables above. + #[clap(long = "pager")] + /// Which pager to use. + /// + /// The default pager is `less`. You can also change pager by setting the environment variables + /// DELTA_PAGER, BAT_PAGER, or PAGER (and that is their order of priority). This option + /// overrides all environment variables above. pub pager: Option<String>, - /// Whether to use a pager when displaying output. Options are: auto, always, and never. - #[structopt(long = "paging", default_value = "auto")] + #[clap(long = "paging", default_value = "auto")] + /// Whether to use a pager when displaying output. + /// + /// Options are: auto, always, and never. pub paging_mode: String, - /// 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`. - #[structopt(parse(from_os_str))] + #[clap(parse(from_os_str))] + /// 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<PathBuf>, + #[clap(parse(from_os_str))] /// Second file to be compared when delta is being used in diff mode. - #[structopt(parse(from_os_str))] pub plus_file: Option<PathBuf>, - /// Style for removed empty line marker (used only if --minus-style has no background color) - #[structopt( + #[clap( long = "--minus-empty-line-marker-style", default_value = "normal auto" )] + /// Style string for removed empty line marker. + /// + /// Used only if --minus-style has no background color. pub minus_empty_line_marker_style: String, - /// Style for added empty line marker (used only if --plus-style has no background color) - #[structopt(long = "--plus-empty-line-marker-style", default_value = "normal auto")] + #[clap(long = "--plus-empty-line-marker-style", default_value = "normal auto")] + /// Style string for added empty line marker. + /// + /// Used only if --plus-style has no background color. pub plus_empty_line_marker_style: String, - /// Style for whitespace errors. Defaults to color.diff.whitespace if that is set in git - /// config, or else 'magenta reverse'. - #[structopt(long = "whitespace-error-style", default_value = "auto auto")] + #[clap(long = "whitespace-error-style", default_value = "auto auto")] + /// Style string for whitespace errors. + /// + /// Defaults to color.diff.whitespace if that is set in git config, or else 'magenta reverse'. pub whitespace_error_style: String, - #[structopt(long = "line-buffer-size", default_value = "32")] - /// Size of internal line buffer. Delta compares the added and removed versions of nearby lines - /// in order to detect and highlight changes at the level of individual words/tokens. - /// Therefore, nearby lines must be buffered internally before they are painted and emitted. - /// Increasing this value might improve highlighting of some large diff hunks. However, setting - /// this to a high value will adversely affect delta's performance when entire files are - /// added/removed. + #[clap(long = "line-buffer-size", default_value = "32")] + /// Size of internal line buffer. + /// + /// Delta compares the added and removed versions of nearby lines in order to detect and + /// highlight changes at the level of individual words/tokens. Therefore, nearby lines must be + /// buffered internally before they are painted and emitted. Increasing this value might improve + /// highlighting of some large diff hunks. However, setting this to a high value will adversely + /// affect delta's performance when entire files are added/removed. pub line_buffer_size: usize, - #[structopt(long = "minus-color")] + #[clap(long = "minus-color")] /// Deprecated: use --minus-style='normal my_background_color'. pub deprecated_minus_background_color: Option<String>, - #[structopt(long = "minus-emph-color")] + #[clap(long = "minus-emph-color")] /// Deprecated: use --minus-emph-style='normal my_background_color'. pub deprecated_minus_emph_background_color: Option<String>, - #[structopt(long = "plus-color")] + #[clap(long = "plus-color")] /// Deprecated: Use --plus-style='syntax my_background_color' to change the background color /// while retaining syntax-highlighting. pub deprecated_plus_background_color: Option<String>, - #[structopt(long = "plus-emph-color")] + #[clap(long = "plus-emph-color")] /// Deprecated: Use --plus-emph-style='syntax my_background_color' to change the background /// color while retaining syntax-highlighting. pub deprecated_plus_emph_background_color: Option<String>, - #[structopt(long = "highlight-removed")] + #[clap(long = "highlight-removed")] /// Deprecated: use --minus-style='syntax'. pub deprecated_highlight_minus_lines: bool, - #[structopt(long = "commit-color")] + #[clap(long = "commit-color")] /// Deprecated: use --commit-style='my_foreground_color' /// --commit-decoration-style='my_foreground_color'. pub deprecated_commit_color: Option<String>, - #[structopt(long = "file-color")] + #[clap(long = "file-color")] /// Deprecated: use --file-style='my_foreground_color' /// --file-decoration-style='my_foreground_color'. pub deprecated_file_color: Option<String>, - #[structopt(long = "hunk-style")] + #[clap(long = "hunk-style")] /// Deprecated: synonym of --hunk-header-decoration-style. pub deprecated_hunk_style: Option<String>, - #[structopt(long = "hunk-color")] + #[clap(long = "hunk-color")] /// Deprecated: use --hunk-header-style='my_foreground_color' /// --hunk-header-decoration-style='my_foreground_color'. pub deprecated_hunk_color: Option<String>, - #[structopt(long = "theme")] + #[clap(long = "theme")] /// Deprecated: use --syntax-theme. pub deprecated_theme: Option<String>, - #[structopt(skip)] + #[clap(skip)] pub computed: ComputedValues, - #[structopt(skip)] + #[clap(skip)] pub git_config: Option<GitConfig>, - #[structopt(skip)] + #[clap(skip)] pub git_config_entries: HashMap<String, GitConfigEntry>, } @@ -882,7 +995,7 @@ impl Opt { git_config: Option<GitConfig>, assets: HighlightingAssets, ) -> Self { - Self::from_clap_and_git_config(Self::clap().get_matches(), git_config, assets) + Self::from_clap_and_git_config(Self::into_app().get_matches(), git_config, assets) } pub fn from_iter_and_git_config<I>(iter: I, git_config: Option<GitConfig>) -> Self @@ -891,7 +1004,7 @@ impl Opt { I::Item: Into<OsString> + Clone, { let assets = HighlightingAssets::new(); - Self::from_clap_and_git_config(Self::clap().get_matches_from(iter), git_config, assets) + Self::from_clap_and_git_config(Self::into_app().get_matches_from(iter), git_config, assets) } fn from_clap_and_git_config( @@ -899,28 +1012,29 @@ impl Opt { mut git_config: Option<GitConfig>, assets: HighlightingAssets, ) -> Self { - let mut opt = Opt::from_clap(&arg_matches); + let mut opt = Opt::from_arg_matches(&arg_matches) + .unwrap_or_else(|_| delta_unreachable("Opt::from_arg_matches failed")); options::rewrite::apply_rewrite_rules(&mut opt, &arg_matches); options::set::set_options(&mut opt, &mut git_config, &arg_matches, assets); opt.git_config = git_config; opt } - #[allow(dead_code)] - pub fn get_option_names<'a>() -> HashMap<&'a str, &'a str> { + pub fn get_argument_and_option_names<'a>() -> HashMap<&'a str, &'a str> { itertools::chain( - Self::clap() - .p - .opts - .iter() - .map(|opt| (opt.b.name, opt.s.long.unwrap())), - Self::clap() - .p - .flags - .iter() - .map(|opt| (opt.b.name, opt.s.long.unwrap())), + Self::into_app().get_opts(), + Self::into_app().get_arguments(), ) - .filter(|(name, _)| !IGNORED_OPTION_NAMES.contains(name)) + .filter_map(|arg| match (arg.get_name(), arg.get_long()) { + (name, Some(long)) => { + if IGNORED_OPTION_NAMES.contains(name) { + None + } else { + Some((name, long)) + } + } + _ => None, + }) .collect() } } |
