1#![cfg(feature = "paging")]
4use std::process::Command;
6pub fn retrieve_less_version(less_path: &dyn AsRef<OsStr>) -> Option<usize> {
7 let cmd = Command::new(less_path).arg("--version").output().ok()?;
8 parse_less_version(&cmd.stdout)
11fn parse_less_version(output: &[u8]) -> Option<usize> {
12 if output.starts_with(b"less ") {
13 let version = std::str::from_utf8(&output[5..]).ok()?;
14 let end = version.find(' ')?;
15 version[..end].parse::<usize>().ok()
22fn test_parse_less_version_487() {
23 let output = b"less 487 (GNU regular expressions)
24Copyright (C) 1984-2016 Mark Nudelman
26less comes with NO WARRANTY, to the extent permitted by law.
27For information about the terms of redistribution,
28see the file named README in the less distribution.
29Homepage: http://www.greenwoodsoftware.com/less";
31 assert_eq!(Some(487), parse_less_version(output));
35fn test_parse_less_version_529() {
36 let output = b"less 529 (Spencer V8 regular expressions)
37Copyright (C) 1984-2017 Mark Nudelman
39less comes with NO WARRANTY, to the extent permitted by law.
40For information about the terms of redistribution,
41see the file named README in the less distribution.
42Homepage: http://www.greenwoodsoftware.com/less";
44 assert_eq!(Some(529), parse_less_version(output));
48fn test_parse_less_version_551() {
49 let output = b"less 551 (PCRE regular expressions)
50Copyright (C) 1984-2019 Mark Nudelman
52less comes with NO WARRANTY, to the extent permitted by law.
53For information about the terms of redistribution,
54see the file named README in the less distribution.
55Home page: http://www.greenwoodsoftware.com/less";
57 assert_eq!(Some(551), parse_less_version(output));
61fn test_parse_less_version_wrong_program() {
62 let output = b"more from util-linux 2.34";
64 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