-
Notifications
You must be signed in to change notification settings - Fork 43
Use clap-markdown to produce usage in a markdown file. (WIP) #732
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #732 +/- ##
=======================================
- Coverage 76.7% 76.3% -0.5%
=======================================
Files 65 69 +4
Lines 5012 5034 +22
=======================================
- Hits 3846 3841 -5
- Misses 1166 1193 +27 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
src/main.rs
Outdated
@@ -223,3 +237,19 @@ fn generate_completion(shell: &Shell, output_file: &Option<PathBuf>) -> Result<( | |||
|
|||
Ok(()) | |||
} | |||
|
|||
fn generate_markdown(output_file: &Option<PathBuf>) -> Result<(), String> { |
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.
Given we generate markdown via templates, I think this is a bit confusing.
Could we create a binary we run in the build that can output this which is NOT build in the general weaver binary we deploy?
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.
That was my plan, but was having issues doing it in xtask. I will spend some more time now that I have it working, about how best to extract it there. I wanted to solicit feedback and help with that, and see if this was something wanted as well, and this was the first pass.
Thanks for the 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.
I'm not as efficient or comprehensive with cargo as I'd like to be. @lquerel is probably best suited to guide that, but yeah it would be desired and glad to know you thought about 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.
I like the idea of having this Markdown command in an xtask. For it to work, I think the following steps are necessary:
- Add a local dependency to the main Weaver project source in the xtask’s dependencies (crates/xtask/Cargo.toml), which should provide access to the code related to the CLI definition.
- Create a new command invoking clap markdown on the src/cli.rs
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 have tried that, and ran into quite a bit of issues, and tried a bunch of work arounds I saw online, but not were working.
I have a commit locally that moves all the clap code to its own crate, and then I depend on just that crate in the xtask. I am cleaning it up to push up as its own commit, so we can revert it if necessary, but as more of a discussion on the changes.
I also did look at using https://crates.io/crates/clap_mangen, but due to the sub commands and sub commands on those, I was running into issues on trying to have it generate all the man pages. Would creating man pages be something we would want to tackle as well? We can move that to a different PR.
This is a POC and a WIP of using clap-markdown to produce usage.md. I am submitting this draft PR as a request for feedback if this is something desired.
This does highlight some updates to the doc strings that clap uses for help that should be addressed in making it consistent as it relates to formatting, and the style of the content.
If we can get this to work, we can also look at clap_mangen to produce a man page for weaver.
Ideally this would be an xtask command, and part of the build process, so it keeps the docs up to date. I could not figure a way out how to best do that inside of xtask, given the way clap-markdown works with the
Cli
struct. I did consider putting this inbuild.rs
, but clap_mangen suggested an xtask, so I figured it makes sense for both to follow the same advise.