Debian Codegraph @

src/subcommands/external.rs

raw symbols SCIP
1 use craterust-analyzer cargo git-delta 0.19.2 crate/::clirust-analyzer cargo git-delta 0.19.2 cli/::Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#;
2 use claprust-analyzer cargo clap 4.5.60 crate/::CommandFactoryrust-analyzer cargo clap_builder 4.5.60 derive/CommandFactory#;
3 use claprust-analyzer cargo clap 4.5.60 crate/::{ArgMatchesrust-analyzer cargo clap_builder 4.5.60 parser/matches/arg_matches/ArgMatches#, Errorrust-analyzer cargo clap_builder 4.5.60 Error#};
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::{OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#, OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#};
5
6 const RGrust-analyzer cargo git-delta 0.19.2 subcommands/external/RG.: &str = "rg";
7 const GITrust-analyzer cargo git-delta 0.19.2 subcommands/external/GIT.: &str = "git";
8 pub const SUBCOMMANDSrust-analyzer cargo git-delta 0.19.2 subcommands/external/SUBCOMMANDS.: &[&str] = &[RGrust-analyzer cargo git-delta 0.19.2 subcommands/external/RG., GITrust-analyzer cargo git-delta 0.19.2 subcommands/external/GIT.];
9
10 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
11 pub enum SubCmdKindrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind# {
12 Gitrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#Git#(Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>), // Some(subcommand) if a git subcommand (git show, git log) was found
13 GitDiffrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#GitDiff#,
14 Diffrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#Diff#,
15 Rgrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#Rg#,
16 Nonerust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#None#,
17 }
18
19 impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for SubCmdKindrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind# {
20 fn fmtrust-analyzer cargo git-delta 0.19.2 subcommands/external/impl#[SubCmdKind][Display]fmt().(&self, formatter: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
21 use SubCmdKindrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#::*;
22 let s = match self {
23 Gitrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#Git#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(arg)) => return formatter.write_fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_fmt().(format_argsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/format_args!!("git {arg}")),
24 Gitrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#Git#(_) => "git",
25 GitDiffrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#GitDiff# => "git diff",
26 Diffrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#Diff# => "diff",
27 Rgrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#Rg# => "rg",
28 Nonerust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#None# => "<none>",
29 };
30 formatter.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(s)
31 }
32 }
33
34 impl stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for SubCmdKindrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind# {
35 fn fmtrust-analyzer cargo git-delta 0.19.2 subcommands/external/impl#[SubCmdKind][Debug]fmt().(&self, formatter: &mut stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
36 let s = match self {
37 SubCmdKindrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#::Gitrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#Git#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(arg)) => {
38 return formatter.write_fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_fmt().(format_argsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/format_args!!("\"git {}\"", arg.escape_debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]escape_debug().()))
39 }
40 _ => formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{self}"),
41 };
42 formatter.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("\"")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
43 formatter.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().(&s)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
44 formatter.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("\"")
45 }
46 }
47
48 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
49 pub struct SubCommandrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCommand# {
50 pub kindrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCommand#kind.: SubCmdKindrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#,
51 pub argsrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCommand#args.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#>,
52 }
53
54 impl SubCommandrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCommand# {
55 pub fn newrust-analyzer cargo git-delta 0.19.2 subcommands/external/impl#[SubCommand]new().(kind: SubCmdKindrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#, args: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#>) -> Selfrust-analyzer cargo git-delta 0.19.2 subcommands/external/impl#[SubCommand] {
56 Selfrust-analyzer cargo git-delta 0.19.2 subcommands/external/impl#[SubCommand] { kindrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCommand#kind., argsrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCommand#args. }
57 }
58
59 pub fn nonerust-analyzer cargo git-delta 0.19.2 subcommands/external/impl#[SubCommand]none().() -> Selfrust-analyzer cargo git-delta 0.19.2 subcommands/external/impl#[SubCommand] {
60 Selfrust-analyzer cargo git-delta 0.19.2 subcommands/external/impl#[SubCommand] {
61 kindrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCommand#kind.: SubCmdKindrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#::Nonerust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#None#,
62 argsrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCommand#args.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![],
63 }
64 }
65
66 pub fn is_nonerust-analyzer cargo git-delta 0.19.2 subcommands/external/impl#[SubCommand]is_none().(&self) -> bool {
67 matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self.kindrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCommand#kind., SubCmdKindrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#::Nonerust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#None#)
68 }
69 }
70
71 /// Find the first arg that is a registered external subcommand and return a
72 /// tuple containing:
73 /// - The args prior to that point (delta can understand these)
74 /// - A SubCommand representing the external subcommand and its subsequent args
75 pub fn extractrust-analyzer cargo git-delta 0.19.2 subcommands/external/extract().(args: &[OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#], orig_error: Errorrust-analyzer cargo clap_builder 4.5.60 Error#) -> (ArgMatchesrust-analyzer cargo clap_builder 4.5.60 parser/matches/arg_matches/ArgMatches#, SubCommandrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCommand#) {
76 for (subcmd_pos, arg) in args.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|a| a.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_str().()).enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
77 if SUBCOMMANDSrust-analyzer cargo git-delta 0.19.2 subcommands/external/SUBCOMMANDS..containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&arg) {
78 match Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#::commandrust-analyzer cargo git-delta 0.19.2 cli/impl#[Opt][CommandFactory]command().().try_get_matches_fromrust-analyzer cargo clap_builder 4.5.60 builder/command/impl#[Command]try_get_matches_from().(&args[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#subcmd_pos]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) {
79 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ref e) if e.kindrust-analyzer cargo clap_builder 4.5.60 error/impl#[`Error<F>`]kind().() rust-analyzer cargo clap_builder 4.5.60 error/kind/impl#[ErrorKind][`PartialEq<Self>`]eq().==rust-analyzer cargo clap_builder 4.5.60 error/kind/impl#[ErrorKind][`PartialEq<Self>`]eq(). rust-analyzer cargo clap_builder 4.5.60 error/kind/impl#[ErrorKind][`PartialEq<Self>`]eq().claprust-analyzer cargo clap 4.5.60 crate/::errorrust-analyzer cargo clap_builder 4.5.60 error/::ErrorKindrust-analyzer cargo clap_builder 4.5.60 error/kind/ErrorKind#::DisplayVersionrust-analyzer cargo clap_builder 4.5.60 error/kind/ErrorKind#DisplayVersion# => {
80 unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!("version handled by caller");
81 }
82 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ref e) if e.kindrust-analyzer cargo clap_builder 4.5.60 error/impl#[`Error<F>`]kind().() rust-analyzer cargo clap_builder 4.5.60 error/kind/impl#[ErrorKind][`PartialEq<Self>`]eq().==rust-analyzer cargo clap_builder 4.5.60 error/kind/impl#[ErrorKind][`PartialEq<Self>`]eq(). rust-analyzer cargo clap_builder 4.5.60 error/kind/impl#[ErrorKind][`PartialEq<Self>`]eq().claprust-analyzer cargo clap 4.5.60 crate/::errorrust-analyzer cargo clap_builder 4.5.60 error/::ErrorKindrust-analyzer cargo clap_builder 4.5.60 error/kind/ErrorKind#::DisplayHelprust-analyzer cargo clap_builder 4.5.60 error/kind/ErrorKind#DisplayHelp# => {
83 unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!("help handled by caller");
84 }
85 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(matches) => {
86 let (subcmd_args_index, kind, subcmd) = if arg rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().RGrust-analyzer cargo git-delta 0.19.2 subcommands/external/RG. {
87 (subcmd_pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1, SubCmdKindrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#::Rgrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#Rg#, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![RGrust-analyzer cargo git-delta 0.19.2 subcommands/external/RG., "--json"])
88 } else if arg rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().GITrust-analyzer cargo git-delta 0.19.2 subcommands/external/GIT. {
89 let subcmd_args_index = subcmd_pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1;
90 let git_subcmd = args
91 .getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(subcmd_args_index)
92 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|cmd| OsStrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsStr#::to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_str().(cmd))
93 .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|cmd| {
94 if cmd.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("-") {
95 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
96 } else {
97 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cmd.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
98 }
99 });
100 (
101 subcmd_args_index,
102 SubCmdKindrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#::Gitrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#Git#(git_subcmd),
103 // git does not start the pager and sees that it does not write to a
104 // terminal, so by default it will not use colors. Override it:
105 vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![GITrust-analyzer cargo git-delta 0.19.2 subcommands/external/GIT., "-c", "color.ui=always"],
106 )
107 } else {
108 unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!("arg must be in SUBCOMMANDS");
109 };
110
111 let subcmd = subcmd
112 .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().()
113 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`From<&T>`]from().)
114 .chainrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#chain().(args[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().subcmd_args_index..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`From<&T>`]from().))
115 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
116
117 return (matches, SubCommandrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCommand#::newrust-analyzer cargo git-delta 0.19.2 subcommands/external/impl#[SubCommand]new().(kind, subcmd));
118 }
119 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => {
120 // part before the subcommand failed to parse, report that error
121 #[cfg(not(test))]
122 orig_error.exit();
123 #[cfg(test)]
124 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("parse error before subcommand ");
125 }
126 }
127 }
128 }
129 // no valid subcommand found, exit with the original error
130 #[cfg(not(test))]
131 orig_error.exit();
132 #[cfg(test)]
133 {
134 let _ = orig_error;
135 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("unexpected delta argument");
136 }
137 }
138
139 #[cfg(test)]
140 mod testrust-analyzer cargo git-delta 0.19.2 subcommands/external/test/ {
141 use superrust-analyzer cargo git-delta 0.19.2 subcommands/external/::RGrust-analyzer cargo git-delta 0.19.2 subcommands/external/RG.;
142 use craterust-analyzer cargo git-delta 0.19.2 crate/::ansirust-analyzer cargo git-delta 0.19.2 ansi/::strip_ansi_codesrust-analyzer cargo git-delta 0.19.2 ansi/strip_ansi_codes().;
143 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#;
144 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#;
145
146 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
147 #[ignore] // reachable with --ignored, useful with --nocapture
148 fn test_subcmd_kind_formatterrust-analyzer cargo git-delta 0.19.2 subcommands/external/test/test_subcmd_kind_formatter().() {
149 use superrust-analyzer cargo git-delta 0.19.2 subcommands/external/::SubCmdKindrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#::*;
150 for s in [
151 Gitrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#Git#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("foo".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())),
152 Gitrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#Git#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("c\"'${}".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())),
153 Gitrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#Git#(Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#::Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
154 GitDiffrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#GitDiff#,
155 Diffrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#Diff#,
156 Rgrust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#Rg#,
157 Nonerust-analyzer cargo git-delta 0.19.2 subcommands/external/SubCmdKind#None#,
158 ] {
159 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("{0} / {0:?} ", s);
160 }
161 }
162
163 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
164 #[should_panic(expected = "unexpected delta argument")]
165 fn just_delta_argument_errorrust-analyzer cargo git-delta 0.19.2 subcommands/external/test/just_delta_argument_error().() {
166 let mut writer = Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]new().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]);
167 let runargs = [
168 "--Invalid_Delta_Args",
169 "abcdefg",
170 "-C1",
171 "--Bad_diff_Args_ignored",
172 ]
173 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
174 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`From<&T>`]from().)
175 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>();
176 craterust-analyzer cargo git-delta 0.19.2 crate/::run_apprust-analyzer cargo git-delta 0.19.2 run_app().(runargs, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&mut writer)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
177 }
178
179 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
180 #[should_panic(expected = "parse error before subcommand")]
181 fn subcommand_found_but_delta_argument_errorrust-analyzer cargo git-delta 0.19.2 subcommands/external/test/subcommand_found_but_delta_argument_error().() {
182 let mut writer = Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]new().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]);
183 let runargs = [
184 "--Invalid_Delta_Args",
185 "git",
186 "show",
187 "-C1",
188 "--Bad_diff_Args_ignored",
189 ]
190 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
191 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`From<&T>`]from().)
192 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>();
193 craterust-analyzer cargo git-delta 0.19.2 crate/::run_apprust-analyzer cargo git-delta 0.19.2 run_app().(runargs, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&mut writer)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
194 }
195
196 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
197 fn subcommand_rgrust-analyzer cargo git-delta 0.19.2 subcommands/external/test/subcommand_rg().() {
198 #[cfg(windows)]
199 // `resolve_binary` only works on windows
200 if grep_clirust-analyzer cargo grep-cli 0.1.12 crate/::resolve_binaryrust-analyzer cargo grep-cli 0.1.12 decompress/resolve_binary().(RGrust-analyzer cargo git-delta 0.19.2 subcommands/external/RG.).is_err() {
201 return;
202 }
203
204 #[cfg(unix)]
205 // resolve `rg` binary by walking PATH
206 if stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::var_osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var_os().("PATH")
207 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]filter().(|p| {
208 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::split_pathsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/split_paths().(&p)
209 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|p| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().p.as_os_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]as_os_str().().is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]is_empty().())
210 .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|p| p.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(RGrust-analyzer cargo git-delta 0.19.2 subcommands/external/RG.).metadatarust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]metadata().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().())
211 .anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#any().(|md| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().md.is_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[Metadata]is_dir().())
212 })
213 .is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().()
214 {
215 return;
216 }
217
218 let mut writer = Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]new().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]);
219 let needle = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}{}", "Y40ii4RihK6", "lHiK4BDsGS").to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
220 // --minus-style has no effect, just for cmdline parsing
221 let runargs = [
222 "--minus-style",
223 "normal",
224 "rg",
225 &needle,
226 "src/",
227 "-N",
228 "-C",
229 "2",
230 "-C0",
231 ]
232 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
233 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`From<&T>`]from().)
234 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>();
235 let exit_code = craterust-analyzer cargo git-delta 0.19.2 crate/::run_apprust-analyzer cargo git-delta 0.19.2 run_app().(runargs, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&mut writer)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
236 let rg_output = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(writer.get_refrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]get_ref().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
237 let mut lines = rg_output.linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().();
238 // eprintln!("{}", rg_output);
239 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
240 r#"src/utils/process.rs "#,
241 strip_ansi_codesrust-analyzer cargo git-delta 0.19.2 ansi/strip_ansi_codes().(lines.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Lines<'a>`][Iterator]next().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("line 1"))
242 );
243 let line2 = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(r#" .join("{}x");"#, needle);
244 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(line2, strip_ansi_codesrust-analyzer cargo git-delta 0.19.2 ansi/strip_ansi_codes().(lines.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Lines<'a>`][Iterator]next().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("line 2")));
245 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(exit_code, 0);
246 }
247
248 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
249 fn subcommand_git_cat_filerust-analyzer cargo git-delta 0.19.2 subcommands/external/test/subcommand_git_cat_file().() {
250 let mut writer = Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]new().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]);
251
252 // only 39 of the 40 long git hash, rev-parse doesn't look up full hashes
253 let runargs = "git rev-parse 5a4361fa037090adf729ab3f161832d969abc57"
254 .splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(' ')
255 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`From<&T>`]from().)
256 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>();
257 let exit_code = craterust-analyzer cargo git-delta 0.19.2 crate/::run_apprust-analyzer cargo git-delta 0.19.2 run_app().(runargs, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&mut writer)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
258 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(exit_code == 0 || exit_code == 128);
259
260 // ref not found, probably a shallow git clone
261 if exit_code rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().128 {
262 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!(" Commit for test not found (shallow git clone?), skipping.");
263 return;
264 }
265
266 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
267 "5a4361fa037090adf729ab3f161832d969abc576\n",
268 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(writer.get_refrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]get_ref().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
269 );
270
271 let mut writer = Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]new().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]);
272
273 let runargs = "git cat-file -p 5a4361fa037090adf729ab3f161832d969abc576:src/main.rs"
274 .splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().(' ')
275 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`From<&T>`]from().)
276 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>();
277 let exit_code = craterust-analyzer cargo git-delta 0.19.2 crate/::run_apprust-analyzer cargo git-delta 0.19.2 run_app().(runargs, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&mut writer)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
278 let hello_world = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(writer.get_refrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]get_ref().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
279 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
280 hello_world,
281 r#"fn main() {
282 println!("Hello, world!");
283 }
284 "#
285 );
286 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(exit_code, 0);
287 }
288 }