mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
pr: add last page option in +page
This commit is contained in:
parent
3be5dc6923
commit
4bf5b86cde
2 changed files with 26 additions and 3 deletions
21
src/pr/pr.rs
21
src/pr/pr.rs
|
@ -598,10 +598,11 @@ fn build_options(
|
||||||
};
|
};
|
||||||
|
|
||||||
// +page option is less priority than --pages
|
// +page option is less priority than --pages
|
||||||
let re = Regex::new(r"\s*\+(\d+)\s*").unwrap();
|
let re = Regex::new(r"\s*\+(\d+:*\d*)\s*").unwrap();
|
||||||
let start_page_in_plus_option: usize = match re.captures(&free_args).map(|i| {
|
let start_page_in_plus_option: usize = match re.captures(&free_args).map(|i| {
|
||||||
let unparsed_num = i.get(1).unwrap().as_str().trim();
|
let unparsed_num = i.get(1).unwrap().as_str().trim();
|
||||||
unparsed_num.parse::<usize>().map_err(|_e| {
|
let x: Vec<&str> = unparsed_num.split(":").collect();
|
||||||
|
x[0].to_string().parse::<usize>().map_err(|_e| {
|
||||||
PrError::EncounteredErrors(format!("invalid {} argument '{}'", "+", unparsed_num))
|
PrError::EncounteredErrors(format!("invalid {} argument '{}'", "+", unparsed_num))
|
||||||
})
|
})
|
||||||
}) {
|
}) {
|
||||||
|
@ -609,6 +610,20 @@ fn build_options(
|
||||||
_ => 1,
|
_ => 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let end_page_in_plus_option: Option<usize> = match re
|
||||||
|
.captures(&free_args)
|
||||||
|
.map(|i| i.get(1).unwrap().as_str().trim())
|
||||||
|
.filter(|i| i.contains(":"))
|
||||||
|
.map(|unparsed_num| {
|
||||||
|
let x: Vec<&str> = unparsed_num.split(":").collect();
|
||||||
|
x[1].to_string().parse::<usize>().map_err(|_e| {
|
||||||
|
PrError::EncounteredErrors(format!("invalid {} argument '{}'", "+", unparsed_num))
|
||||||
|
})
|
||||||
|
}) {
|
||||||
|
Some(res) => Some(res?),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
|
||||||
let start_page: usize = match matches
|
let start_page: usize = match matches
|
||||||
.opt_str(PAGE_RANGE_OPTION)
|
.opt_str(PAGE_RANGE_OPTION)
|
||||||
.map(|i| {
|
.map(|i| {
|
||||||
|
@ -631,7 +646,7 @@ fn build_options(
|
||||||
.map(invalid_pages_map)
|
.map(invalid_pages_map)
|
||||||
{
|
{
|
||||||
Some(res) => Some(res?),
|
Some(res) => Some(res?),
|
||||||
_ => None,
|
_ => end_page_in_plus_option,
|
||||||
};
|
};
|
||||||
|
|
||||||
if end_page.is_some() && start_page > end_page.unwrap() {
|
if end_page.is_some() && start_page > end_page.unwrap() {
|
||||||
|
|
|
@ -273,6 +273,14 @@ fn test_with_page_range() {
|
||||||
expected_test_file_path1,
|
expected_test_file_path1,
|
||||||
vec![(&"{last_modified_time}".to_string(), &value)],
|
vec![(&"{last_modified_time}".to_string(), &value)],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["+15:17", test_file_path])
|
||||||
|
.succeeds()
|
||||||
|
.stdout_is_templated_fixture(
|
||||||
|
expected_test_file_path1,
|
||||||
|
vec![(&"{last_modified_time}".to_string(), &value)],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue