@@ -0,0 +1,49 @@
1+use std::process::Command;
3+pub fn retrieve_less_version() -> Option<usize> {
4+ let cmd = Command::new("less").arg("--version").output().ok()?;
5+ parse_less_version(&cmd.stdout)
8+fn parse_less_version(output: &[u8]) -> Option<usize> {
9+ if output.starts_with(b"less ") {
10+ let version = std::str::from_utf8(&output[5..]).ok()?;
11+ let end = version.find(' ')?;
12+ version[..end].parse::<usize>().ok()
19+fn test_parse_less_version_487() {
20+ let output = b"less 487 (GNU regular expressions)
21+Copyright (C) 1984-2016 Mark Nudelman
23+less comes with NO WARRANTY, to the extent permitted by law.
24+For information about the terms of redistribution,
25+see the file named README in the less distribution.
26+Homepage: http://www.greenwoodsoftware.com/less";
28+ assert_eq!(Some(487), parse_less_version(output));
32+fn test_parse_less_version_551() {
33+ let output = b"less 551 (PCRE regular expressions)
34+Copyright (C) 1984-2019 Mark Nudelman
36+less comes with NO WARRANTY, to the extent permitted by law.
37+For information about the terms of redistribution,
38+see the file named README in the less distribution.
39+Home page: http://www.greenwoodsoftware.com/less";
41+ assert_eq!(Some(551), parse_less_version(output));
45+fn test_parse_less_version_wrong_program() {
46+ let output = b"more from util-linux 2.34";
48+ assert_eq!(None, parse_less_version(output));