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

Add examples to cli --help #5388

Merged
merged 56 commits into from
Jan 10, 2024
Merged

Add examples to cli --help #5388

merged 56 commits into from
Jan 10, 2024

Conversation

crodas
Copy link
Contributor

@crodas crodas commented Dec 13, 2023

Description

Fixes #5398, #5374. This PR depends on #5433

Add examples to our --help cli. The examples are defined through the a macro forc::cli_examples { } and each of these examples is part of the the test suite of the crate. This is done to ensure the documentation is always up to date or updated whenever the tests are not passing.

All the CLI examples should be provided with the forc::cli_examples! macro.

forc::cli_examples! {
    [ Do something and expect the exit to be 0 => bin-name " arg1 arg 2"  ],
    [ Do something and check stdout or stderr => bin-name " arg1 arg 2" => r#"Expected output with regex"# ],
}

The above example will create two unit tests that will be run as part of the cargo test inside the project. The unit test will be done with an external invocation, meaning it can be treated like an end-to-end test instead of a unit test. If the binary interface changes, the tests should fail, forcing the developer to either update the tests (which is the documentation) or keep them backward compatible. The ultimate goal is to have documentation that is up to date, enforced by the github actions/unit test.

Last bit not least the macro will create a help() function which is local to the file, this file does the printing with --help is invoked. It should be used as follows:

#[clap(bin_name = "forc name", version, after_help = help())]
pub struct Command {
   ...
}

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@crodas crodas self-assigned this Dec 13, 2023
@crodas crodas force-pushed the plugins-examples branch 6 times, most recently from 542fc12 to 973e38d Compare December 15, 2023 17:24
@crodas crodas marked this pull request as ready for review December 15, 2023 17:39
@crodas crodas requested a review from a team December 15, 2023 17:39
@crodas
Copy link
Contributor Author

crodas commented Dec 15, 2023

Screen.Recording.2023-12-15.at.14.50.30.mov

@crodas crodas enabled auto-merge (squash) December 15, 2023 17:53
Copy link
Member

@kayagokalp kayagokalp left a comment

Choose a reason for hiding this comment

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

This is going to be really nice! Thanks for the testing infra for examples as well. It seems like we are touching forc-crypto, forc-doc and forc itself in this PR, are we planning to touch to forc-client, forc-submit as well? If so let's mark this as a draft if you want to break it into couple of ones we should probably update the title and description.

@kayagokalp kayagokalp requested a review from a team December 15, 2023 18:05
@crodas crodas disabled auto-merge December 15, 2023 18:52
@crodas crodas marked this pull request as draft December 15, 2023 18:52
@crodas
Copy link
Contributor Author

crodas commented Dec 15, 2023

This is going to be really nice! Thanks for the testing infra for examples as well. It seems like we are touching forc-crypto, forc-doc and forc itself in this PR, are we planning to touch to forc-client, forc-submit as well? If so let's mark this as a draft if you want to break it into couple of ones we should probably update the title and description.

I am adding more examples now

@crodas crodas force-pushed the plugins-examples branch 3 times, most recently from e122b44 to 5aa71ac Compare December 16, 2023 04:49
The commands wil be broken into multiple lines automatically
@crodas crodas force-pushed the plugins-examples branch 4 times, most recently from 45bd774 to 3832995 Compare December 16, 2023 05:20
kayagokalp
kayagokalp previously approved these changes Jan 8, 2024
Copy link
Member

@kayagokalp kayagokalp left a comment

Choose a reason for hiding this comment

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

I think examples look comprehensive enough! Nice work, I can approve again after josh's comments

@crodas
Copy link
Contributor Author

crodas commented Jan 8, 2024

Todo:

  • Move the macro definition to the for utils
  • forc-test
  • forc-tx
  • forc-doc
  • forc-deploy
  • forc-submit

Copy link
Member

@JoshuaBatty JoshuaBatty left a comment

Choose a reason for hiding this comment

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

Nice work

Copy link
Member

@sdankel sdankel left a comment

Choose a reason for hiding this comment

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

:shipit:

@crodas crodas merged commit fb06a8f into master Jan 10, 2024
35 checks passed
@crodas crodas deleted the plugins-examples branch January 10, 2024 05:47
crodas added a commit that referenced this pull request Jan 23, 2024
## Description

Add recover-public-key to forc-crypto

This function is ported from
FuelLabs/forc-wallet#152

This PR depends on #5388

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhance --help examples for forc plugins
5 participants