-
Notifications
You must be signed in to change notification settings - Fork 1
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
Implement pgxn_meta CLI #11
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## rm-spec #11 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 2 +1
Lines 43 114 +71
=========================================
+ Hits 43 114 +71 ☔ View full report in Codecov by Sentry. |
31642e9
to
f13450d
Compare
src/main.rs
Outdated
|
||
// Minimal main function; logical is all in run. | ||
fn main() -> Result<ExitCode, Box<dyn Error>> { | ||
run(io::stdout(), env::args_os().collect::<Vec<_>>()) |
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.
run(io::stdout(), env::args_os().collect::<Vec<_>>()) | |
run(io::stdout(), env::args_os()) |
Can likely get away from collect
ing here since args_os
already returns an iterator
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.
Oh, thanks! Done in 9e072a1.
src/main.rs
Outdated
let meta: Value = serde_json::from_reader(f)?; | ||
let mut v = Validator::new(); | ||
if let Err(e) = v.validate(&meta) { | ||
panic!("{file} {e}"); |
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.
Why panicking instead of returning the error?
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.
Because the error references values in meta, so can't be returned. It has since occurred to me that I could make a new error from a string and return that, but saw no urgency in it.
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.
Made that change in 6fb932d
Keep it simple right now, mimicking [validate_pgxn_meta], although the `--man` option currently doesn't do much. Use lexopt for argument parsing, since it's super simple like this use case. Avoid [std::process::exit] and set a boolean to return [std::process::ExitCode] when the app should exit without processing a file. This makes it easier to test things, since the functions to print the usage statement or version don't exit. Include tests that cover every bit of functionality, including the `main()` function. Add `corpus/invalid.json` to properly test validation failure. Try to improve the coveralls formatting. [validate_pgxn_meta]: https://metacpan.org/pod/validate_pgxn_meta [std::process::exit]: https://doc.rust-lang.org/stable/std/process/fn.exit.html [std::process::ExitCode]: https://doc.rust-lang.org/stable/std/process/struct.ExitCode.html
Keep it simple right now, mimicking validate_pgxn_meta, although the
--man
option currently doesn't do much. Use lexopt for argument parsing, since it's super simple like this use case.Avoid std::process::exit and set a boolean to return std::process::ExitCode when the app should exit without processing a file. This makes it easier to test things, since the functions to print the usage statement or version don't exit.
Include tests that cover every bit of functionality, including the
main()
function. Addcorpus/invalid.json
to properly test validation failure. Try to improve the coveralls formatting.