| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#; |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#; |
| 3 | |
| 4 | pub fn retrieve_less_versionrust-analyzer cargo git-delta 0.19.2 utils/bat/less/retrieve_less_version().(less_path: PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize> { |
| 5 | let cmd = Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]new().(less_path).argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().("--version").outputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]output().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 6 | parse_less_versionrust-analyzer cargo git-delta 0.19.2 utils/bat/less/parse_less_version().(&cmd.stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#stdout.) |
| 7 | } |
| 8 | |
| 9 | fn parse_less_versionrust-analyzer cargo git-delta 0.19.2 utils/bat/less/parse_less_version().(output: &[u8]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize> { |
| 10 | if output.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]starts_with().(b"less ") { |
| 11 | let version = 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().(&output[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().5..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().).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 12 | let end = version.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(|c: char| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().c.is_ascii_digitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_ascii_digit().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 13 | version[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#end]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<usize>().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().() |
| 14 | } else { |
| 15 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | #[cfg(test)] |
| 20 | mod testsrust-analyzer cargo git-delta 0.19.2 utils/bat/less/tests/ { |
| 21 | use superrust-analyzer cargo git-delta 0.19.2 utils/bat/less/::parse_less_versionrust-analyzer cargo git-delta 0.19.2 utils/bat/less/parse_less_version().; |
| 22 | |
| 23 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 24 | fn test_parse_less_version_487rust-analyzer cargo git-delta 0.19.2 utils/bat/less/tests/test_parse_less_version_487().() { |
| 25 | let output = b"less 487 (GNU regular expressions) |
| 26 | Copyright (C) 1984-2016 Mark Nudelman |
| 27 | |
| 28 | less comes with NO WARRANTY, to the extent permitted by law. |
| 29 | For information about the terms of redistribution, |
| 30 | see the file named README in the less distribution. |
| 31 | Homepage: http://www.greenwoodsoftware.com/less"; |
| 32 | |
| 33 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(487), parse_less_versionrust-analyzer cargo git-delta 0.19.2 utils/bat/less/parse_less_version().(output)); |
| 34 | } |
| 35 | |
| 36 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 37 | fn test_parse_less_version_529rust-analyzer cargo git-delta 0.19.2 utils/bat/less/tests/test_parse_less_version_529().() { |
| 38 | let output = b"less 529 (Spencer V8 regular expressions) |
| 39 | Copyright (C) 1984-2017 Mark Nudelman |
| 40 | |
| 41 | less comes with NO WARRANTY, to the extent permitted by law. |
| 42 | For information about the terms of redistribution, |
| 43 | see the file named README in the less distribution. |
| 44 | Homepage: http://www.greenwoodsoftware.com/less"; |
| 45 | |
| 46 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(529), parse_less_versionrust-analyzer cargo git-delta 0.19.2 utils/bat/less/parse_less_version().(output)); |
| 47 | } |
| 48 | |
| 49 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 50 | fn test_parse_less_version_551rust-analyzer cargo git-delta 0.19.2 utils/bat/less/tests/test_parse_less_version_551().() { |
| 51 | let output = b"less 551 (PCRE regular expressions) |
| 52 | Copyright (C) 1984-2019 Mark Nudelman |
| 53 | |
| 54 | less comes with NO WARRANTY, to the extent permitted by law. |
| 55 | For information about the terms of redistribution, |
| 56 | see the file named README in the less distribution. |
| 57 | Home page: http://www.greenwoodsoftware.com/less"; |
| 58 | |
| 59 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(551), parse_less_versionrust-analyzer cargo git-delta 0.19.2 utils/bat/less/parse_less_version().(output)); |
| 60 | } |
| 61 | |
| 62 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 63 | fn test_parse_less_version_wrong_programrust-analyzer cargo git-delta 0.19.2 utils/bat/less/tests/test_parse_less_version_wrong_program().() { |
| 64 | let output = b"more from util-linux 2.34"; |
| 65 | |
| 66 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, parse_less_versionrust-analyzer cargo git-delta 0.19.2 utils/bat/less/parse_less_version().(output)); |
| 67 | } |
| 68 | } |