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

Separate hidden and non-hidden commands in lakectl docs #8204

Merged
merged 2 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 53 additions & 6 deletions cmd/lakectl/cmd/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ the Docker container. That is to say, ` + "`localhost`" + ` to a Docker containe
## Command Reference
`

var cliReferenceHiddenCommandsSeparator = `
-------

## Undocumented commands
Copy link
Contributor

Choose a reason for hiding this comment

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

A thought:
This section is pretty much at the top of the file, so it pretty much pops up.
If it can be pushed to the bottom of the file, might be nicer I think…

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure, could you explain on the auto-generated CLI reference file in this PR where things should go?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, I can't think of another option actually...


**note:**
⚠️ These commands are plumbing commands and for internal use only.
Avoid using them unless you're _really_ sure you know what you're doing, or
have been in contact with lakeFS support!
{: .note .note-warning }

`

var cliReferenceHiddenCommandBanner = `**note:**
lakeFS plumbing command. Don't use unless you're _really_ sure you know what you're doing.
{: .note .note-warning }

`

func printOptions(buf *bytes.Buffer, cmd *cobra.Command) error {
flags := cmd.NonInheritedFlags()
flags.SetOutput(buf)
Expand All @@ -103,9 +122,11 @@ func printOptions(buf *bytes.Buffer, cmd *cobra.Command) error {
return nil
}

// this is a version of github.com/spf13/cobra/doc that fits better
// into lakeFS' docs.
func genMarkdownForCmd(cmd *cobra.Command, w io.Writer) error {
// genMarkdownForCmd is a version of github.com/spf13/cobra/doc that fits
// better into lakeFS' docs. It generates documentation for cmd, then for
// its subcommands. topLevel adds a scarier header before those hidden
// subcommands.
func genMarkdownForCmd(cmd *cobra.Command, w io.Writer, topLevel bool) error {
cmd.InitDefaultHelpCmd()
cmd.InitDefaultHelpFlag()

Expand All @@ -115,7 +136,7 @@ func genMarkdownForCmd(cmd *cobra.Command, w io.Writer) error {
buf.WriteString("### " + name + "\n\n")

if cmd.Hidden {
buf.WriteString("**note:** This command is a lakeFS plumbing command. Don't use it unless you're really sure you know what you're doing.\n{: .note .note-warning }\n\n")
buf.WriteString(cliReferenceHiddenCommandBanner)
}

buf.WriteString(cmd.Short + "\n\n")
Expand Down Expand Up @@ -144,11 +165,37 @@ func genMarkdownForCmd(cmd *cobra.Command, w io.Writer) error {
}

// recurse to children
hasHidden := false
for _, c := range cmd.Commands() {
err := genMarkdownForCmd(c, w)
if c.Hidden {
hasHidden = true
continue
}
err := genMarkdownForCmd(c, w, false)
if err != nil {
return err
}
}

if hasHidden {
sep := "\n---------\n"
if topLevel {
sep = cliReferenceHiddenCommandsSeparator
}
_, err := io.WriteString(w, sep)
if err != nil {
return err
}

for _, c := range cmd.Commands() {
if !c.Hidden {
continue
}
err := genMarkdownForCmd(c, w, false)
if err != nil {
return err
}
}
}

return nil
Expand Down Expand Up @@ -176,7 +223,7 @@ var docsCmd = &cobra.Command{
if err != nil {
DieErr(err)
}
err = genMarkdownForCmd(rootCmd, writer)
err = genMarkdownForCmd(rootCmd, writer, true)
if err != nil {
DieErr(err)
}
Expand Down
Loading
Loading