1#![cfg(feature = "paging")]
4use std::process::Command;
6pub fn retrieve_less_version(less_path: &dyn AsRef<OsStr>) -> Option<usize> {
7 let resolved_path = grep_cli::resolve_binary(less_path.as_ref()).ok()?;
9 let cmd = Command::new(resolved_path).arg("--version").output().ok()?;
10 parse_less_version(&cmd.stdout)
13fn parse_less_version(output: &[u8]) -> Option<usize> {
14 if output.starts_with(b"less ") {
15 let version = std::str::from_utf8(&output[5..]).ok()?;
16 let end = version.find(|c: char| !c.is_ascii_digit())?;
17 version[..end].parse::<usize>().ok()
24fn test_parse_less_version_487() {
25 let output = b"less 487 (GNU regular expressions)
26Copyright (C) 1984-2016 Mark Nudelman
28less comes with NO WARRANTY, to the extent permitted by law.
29For information about the terms of redistribution,
30see the file named README in the less distribution.
31Homepage: http://www.greenwoodsoftware.com/less";
33 assert_eq!(Some(487), parse_less_version(output));
37fn test_parse_less_version_529() {
38 let output = b"less 529 (Spencer V8 regular expressions)
39Copyright (C) 1984-2017 Mark Nudelman
41less comes with NO WARRANTY, to the extent permitted by law.
42For information about the terms of redistribution,
43see the file named README in the less distribution.
44Homepage: http://www.greenwoodsoftware.com/less";
46 assert_eq!(Some(529), parse_less_version(output));
50fn test_parse_less_version_551() {
51 let output = b"less 551 (PCRE regular expressions)
52Copyright (C) 1984-2019 Mark Nudelman
54less comes with NO WARRANTY, to the extent permitted by law.
55For information about the terms of redistribution,
56see the file named README in the less distribution.
57Home page: http://www.greenwoodsoftware.com/less";
59 assert_eq!(Some(551), parse_less_version(output));
63fn test_parse_less_version_581_2() {
64 let output = b"less 581.2 (PCRE2 regular expressions)
65Copyright (C) 1984-2021 Mark Nudelman
67less comes with NO WARRANTY, to the extent permitted by law.
68For information about the terms of redistribution,
69see the file named README in the less distribution.
70Home page: https://greenwoodsoftware.com/less";
72 assert_eq!(Some(581), parse_less_version(output));
76fn test_parse_less_version_wrong_program() {
77 let output = b"more from util-linux 2.34";
79 assert_eq!(None, parse_less_version(output));
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list