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
Add arguments from PAGER/BAT_PAGER #354
Conversation
Thank you very much for your contribution! In general, the code-change looks good. It would be great if we could add tests, yes. It's a little bit tricky, because we don't want to rely on the existance of One option could be to write a integration test in the style of #[test]
fn pager() {
bat()
.env("BAT_PAGER", "echo pager-output")
.arg("test.txt")
.arg("--paging=always")
.assert()
.stdout("pager-output\n")
.success();
} There are a few things that we have to test (at least manually):
Concerning the error-handling, I could add that in when the other things are done, if that's okay for you. |
Fixed up on the |
src/output.rs
Outdated
@@ -28,23 +30,27 @@ impl OutputType { | |||
.or_else(|_| env::var("PAGER")) | |||
.unwrap_or(String::from("less")); | |||
|
|||
let less_path = PathBuf::from(&pager); | |||
let pagerflags = shell_words::split(&pager).unwrap_or(vec![pager]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
split
will fail if there is a parse error, for example:
split("less --option='foo") # closing quote is missing
I don't think that unwrap_or
would help in such a case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
src/output.rs
Outdated
let less_path = PathBuf::from(&pager); | ||
let pagerflags = shell_words::split(&pager).unwrap_or(vec![pager]); | ||
|
||
let less_path = PathBuf::from(&pagerflags[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if we pass BAT_PAGER=""
? Does this panic?
Previously, setting BAT_PAGER=""
would disable the pager. I'd like to keep this behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
src/output.rs
Outdated
}; | ||
|
||
process | ||
.args(&pagerflags[1..]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. We should make sure that this does not panic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Solves sharkdp#352 Signed-off-by: Morten Linderud <morten@linderud.pw>
Ah, yes. That's a lot neater then the improvements i sat with locally. |
Thank you for your work! |
I'm a bit unsure of Rust error handling. Probably also missing a test, but lets just ack the code change first maybe.
Solves #352
Signed-off-by: Morten Linderud morten@linderud.pw