Skip to content

Generate CLI docs from Go code #1696

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Conversation

zeke
Copy link
Member

@zeke zeke commented May 29, 2024

This PR generate CLI reference docs programmatically from the Go source code using cobra/doc.

View the docs

https://github.com/replicate/cog/blob/077efdfda59d207ed58601c2b4513e33cda10e00/docs/cli.md

Generate the docs

script/build-cli-docs

To Do

  • Figure out how to get cobra/docs to fold all CLI docs into one markdown file.
  • Improve existing long and example docs in Go commands
  • Configure mkdocs.yml to include CLI docs in https://cog.run site nav
  • Figure out if we can do all the shell-script silliness in a single Go script instead and maybe a make command
  • Update build process (and CONTRIBUTING docs) to generate docs
  • docs/cli.md is an artifact of the build process. How do we get it checked into the repo?

Resolves #433

@zeke
Copy link
Member Author

zeke commented May 29, 2024

@zeke zeke force-pushed the generate-cli-docs-with-cobra branch from ff993c8 to 077efdf Compare May 31, 2024 22:16
@zeke zeke changed the title Generate CLI docs with Cobra [WIP] Generate CLI docs from Go code May 31, 2024
@@ -0,0 +1,40 @@
#!/bin/sh
Copy link
Member Author

Choose a reason for hiding this comment

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

This script is a bit heinous. Would love to make it all happen more glamorously in a single Go script, but I'm not a good enough gopher to make that happen.

Halp!?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would make sense to move the docs generation to a dedicated command (see comment above) and add the steps here to the command so it's self container.

I can take a stab at it later today.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed that a separate generate-docs command, in a similar sense to autocompletion scripts would work well here. There's inspiration from the cobra docs themselves. a la https://www.emmanuelgautier.com/blog/snippets/go-cobra-docgen

@zeke zeke marked this pull request as ready for review May 31, 2024 22:23
@zeke zeke requested review from a team and marcusmartins May 31, 2024 22:24
@zeke
Copy link
Member Author

zeke commented May 31, 2024

This is ready for eyes!

It works, but there a few outstanding issues to get it over the finish line. Could use some help from someone with Gopher skills and knowledge of where this new docs build process should slot into the dev/release cycle.

Copy link
Contributor

@marcusmartins marcusmartins left a comment

Choose a reason for hiding this comment

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

Left a few comments. I am happy to look into it today.

err = doc.GenMarkdownTree(cmd, "./docs/tmp")
if err != nil {
log.Fatal(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be moved to a separate command. Otherwise, it creates the docs everytime the main get invoked

@@ -0,0 +1,40 @@
#!/bin/sh
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would make sense to move the docs generation to a dedicated command (see comment above) and add the steps here to the command so it's self container.

I can take a stab at it later today.

@@ -165,6 +166,7 @@ require (
github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727 // indirect
github.com/quasilyte/stdinfo v0.0.0-20220114132959-f7386bf02567 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
Copy link
Contributor

@marcusmartins marcusmartins Jun 3, 2024

Choose a reason for hiding this comment

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

Are you still using the new dependencies here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm actually not sure.. I didn't add them manually. Maybe they got added by cobra/doc?

@zeke zeke marked this pull request as draft June 18, 2024 00:15
@zeke
Copy link
Member Author

zeke commented Jun 18, 2024

Converting this back to a draft. Still worth pursuing, but not a high priority.

@aknoerig
Copy link
Contributor

Asking kindly for someone to push this across the finish line. As a newbie to cog, the lack of systematic docs makes it a bit confusing to get started. Everything centers around the cog CLI, but there's no proper reference for it. It would help a lot to get a better understanding of the cog capabilities, plus I'd really like to know what a command will do before I execute it in my shell. Thanks!

@aron aron removed the request for review from a team October 16, 2024 09:34
@aron
Copy link
Contributor

aron commented Oct 16, 2024

Removing @replicate/cog as the reviewers for the moment as this currently shows up in the review reminders and is non-actionable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLI reference documentation
5 participants