Skip to content
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

Merged
merged 1 commit into from
Aug 6, 2024
Merged

Implement pgxn_meta CLI #11

merged 1 commit into from
Aug 6, 2024

Conversation

theory
Copy link
Member

@theory theory commented Aug 1, 2024

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.

@theory theory self-assigned this Aug 1, 2024
Copy link

codecov bot commented Aug 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (58ffb17) to head (6fb932d).

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.
📢 Have feedback on the report? Share it here.

@theory theory force-pushed the bin branch 6 times, most recently from 31642e9 to f13450d Compare August 3, 2024 13:36
@theory theory added the enhancement New feature or request label Aug 3, 2024
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<_>>())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
run(io::stdout(), env::args_os().collect::<Vec<_>>())
run(io::stdout(), env::args_os())

Can likely get away from collecting here since args_os already returns an iterator

Copy link
Member Author

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}");
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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
Base automatically changed from rm-spec to main August 6, 2024 23:07
@theory theory merged commit 6fb932d into main Aug 6, 2024
12 checks passed
@theory theory deleted the bin branch August 6, 2024 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants