-
Notifications
You must be signed in to change notification settings - Fork 50
Feat/cli as lib #507
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
Feat/cli as lib #507
Conversation
|
todo - rename bin to |
JP-Ellis
left a comment
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.
Just a couple of questions, but looking good!
|
|
||
| ```console | ||
| $ pact_verifier_cli,ignore | ||
| $ pact-verifier,ignore |
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.
Is the ,ignore meant to be there?
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.
So it is there to prevent trycmd from failing, as pact-verifier with no args, prints help but with an exit code of 2
Updating to be --help would probably be better, as it will allow to auto testing and updating with TRYCMD_OVERWRITE=true cargo test
| @@ -1,2 +1,2 @@ | |||
| [package] | |||
| name = "pact_verifier_cli" | |||
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.
I'm wondering... should we take the opportunity to rename this pact-verifier as well? Rust will automatically convert this to pact_verifier within the code.
To preserve compatibility, we can still have a library called pact_verifier_cli which is a shim to pact-verifier?
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.
I like the idea of a shim, but we already have a pact_verifier crate, so that rename might be awkward.
for the mock-server and verifier they have
- pact_verifier / pact_verifier_cli
- pact_mock_server / pact_mock_server_cli
so maybe
- pact-verifier / pact-verifier-cli
- pact-mock-server / pact-mock-server-cli
unless we consolidate the cli functionality into their respective crates.
do we also consider the same the convention for the other crates
- pact-models
- pact-matching
etc
How would the shim work in practise? Interested.
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.
I do definitely agree with using the hyphens given that the majority of our tools are already using hyphens, but it also just slipped my mind that we have a separate pact-verifier crate already... You can disregard my previous comment 😅
I think that separate the CLI and library logic into separate crates make complete sense. E.g., pact-verifier and pact-verifier-cli. So the library can be used without pulling the (typically much heaver) CLI dependencies, and keeping the code clean.
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.
hehe no worries, it a reasonable sized ecosystem so easy to forget!
we have a mix, i would say more snake_case ( pact-plugin-cli / pact-plugin-driver / pact-stub-server / pact-broker-cli are the only kebabs )
https://docs.pact.io/diagrams/ecosystem#rust-goldberg-machine
tl;dr - we can’t change case of existing crates, as they can’t be published to cargo. we can only provide guidance for new crates.
cli in a lib crate could work if deps and code are feature gated, but does increase complexity. a cli suffixed repo is clear in its purpose. if it is also available as a lib, it is for the purpose of composing cli libs.
snake_case here for me is fine as a crate name, as it matches up with how it will be used in rust code, as you need to downcase to import.
it will feel odd when doing cargo install pact_mock_server_cli to install the bin pact-mock-server, but most end users won’t use the binaries with cargo/rust projects, they will install via prebuilt means
anyway after doing some reading of rust rfcs, there is no consensus on convention.
a point that does make renaming moot, we can’t publish crates where they clash with existing name, kebab or snake case
pact_verifier cannot be uploaded to crates to pact-verifier.
if it wasn’t depended on, it could be deleted and republished with the new kebab case name, but our crate popularity precludes that
pact_verifier and pact-verifier are not equiv in cargo. they won’t normalise via cargo install or cargo add, in a Cargo.toml but is normalised to snake case in rust code for imports
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.
The namespace clash is interesting, and turns out, both are translated:
❯ cargo add serde-yaml
Updating crates.io index
warning: translating `serde-yaml` to `serde_yaml`
Adding serde_yaml v0.9.34 to dependencies
Updating crates.io index
Locking 14 packages to latest Rust 1.90.0 compatible versions
❯ cargo add serde_json_fmt
Updating crates.io index
warning: translating `serde_json_fmt` to `serde-json-fmt`
Adding serde-json-fmt v0.1.0 to dependencies
Updating crates.io index
Locking 7 packages to latest Rust 1.90.0 compatible versions
Adding autocfg v1.5.0
Adding memchr v2.7.6
Adding serde-json-fmt v0.1.0
Adding serde_json v1.0.145
Adding smartstring v1.0.1
Adding static_assertions v1.1.0
Adding version_check v0.9.5
So perhaps I'm overthinking 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.
hmm works with cargo add but not cargo install, hmmm.
thanks for checking!
So perhaps I'm overthinking it 😅
If it worked both ways with cargo install, I think it would be quite nice. I think once the binaries are all renamed it'll be alright, it seems like rustaceans will be pretty aware of the wild west of snakes and kebabs at large, and have to adjust accordingly. For everyone else, they just get normalised kebab-case in all the cli's 👍🏾 🎉
Always happy to ponder hehe, overthink away
📝 Summary of Changes
Changes proposed in this pull request:
pact_verifier_clito be consumed as a librarypact_verifier_cliso it can be composed in other clisPart of a series of pull requests
💁 Example
Composed cli: https://github.com/YOU54F/pact_cli/blob/259a268dd9e7fa48ad03c088f7244af7a4c89493/src/cli.rs#L11-L29
Cargo toml: https://github.com/YOU54F/pact_cli/blob/259a268dd9e7fa48ad03c088f7244af7a4c89493/Cargo.toml#L67-L71
🔨 How To Test
output
usage