Skip to content

Commit

Permalink
Separate hidden and non-hidden commands in lakectl docs (#8204)
Browse files Browse the repository at this point in the history
* Separate hidden and non-hidden commands in lakectl docs

Also add a scary banner so people know not to use them.

* Fix .note-warning Jekyll
  • Loading branch information
arielshaqed authored Oct 6, 2024
1 parent c939d71 commit 1837eff
Show file tree
Hide file tree
Showing 2 changed files with 681 additions and 605 deletions.
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
**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

0 comments on commit 1837eff

Please sign in to comment.