8000 `pr`: Move from getopts to clap and fix heuristic for `-n` by tertsdiepraam · Pull Request #3185 · uutils/coreutils · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

pr: Move from getopts to clap and fix heuristic for -n #3185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 5, 2022

Conversation

tertsdiepraam
Copy link
Member

Fixes #3109

Surprisingly, pr didn't use clap yet, so I changed that too. pr has a function to that changes the list of arguments into something that clap can parse. The problem was that it was using a regex that matches to many strings. This is the important change for the fix:

-    let num_regex = Regex::new(r"(.\d+)|(\d+)|^[^-]$").unwrap();
+    let num_regex = Regex::new(r"^.\d*$").unwrap();

A couple of subtle issues remain, however. For example pr -n -5 foo.txt should use - as a separator, but currently -5 is removed from the list of arguments. It should only remove it if the previous element was not -n. The approach to the arguments here might need to be redone eventually.

@tertsdiepraam
Copy link
Member Author

I'll fix the CI warnings later :)

@sylvestre
Copy link
Contributor

I guess you saw

---- test_pr::test_with_stdin stdout ----
current_directory_resolved: 
open: /tmp/.tmpAad6fQ/stdin.log
run: /home/runner/work/coreutils/coreutils/target/debug/coreutils pr --pages=1:2 -n -
open: /tmp/.tmpAad6fQ/stdin.log.expected
thread 'test_pr::test_with_stdin' panicked at 'stdout was 

@sylvestre sylvestre merged commit bb379b5 into uutils:main Mar 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pr: Doesn't allow for omitted optional argument to -n
2 participants
0