github.com/cozy/cozy-stack@v0.0.0-20240603063001-31110fa4cae1/cmd/doc.go (about)

     1  package cmd
     2  
     3  import (
     4  	"github.com/spf13/cobra"
     5  	"github.com/spf13/cobra/doc"
     6  )
     7  
     8  // docCmdGroup represents the doc command
     9  var docCmdGroup = &cobra.Command{
    10  	Use:   "doc <command>",
    11  	Short: "Print the documentation",
    12  	Long:  "Print the documentation about the usage of cozy-stack in command-line",
    13  	RunE: func(cmd *cobra.Command, args []string) error {
    14  		return cmd.Usage()
    15  	},
    16  }
    17  
    18  var manDocCmd = &cobra.Command{
    19  	Use:   "man <directory>",
    20  	Short: "Print the manpages of cozy-stack",
    21  	Long:  `Print the manual pages for using cozy-stack in command-line`,
    22  	Example: `$ mkdir -p ~/share/man
    23  $ export MANPATH=~/share/man:$MANPATH
    24  $ cozy-stack doc man ~/share/man
    25  $ man cozy-stack`,
    26  	RunE: func(cmd *cobra.Command, args []string) error {
    27  		if len(args) != 1 {
    28  			return cmd.Usage()
    29  		}
    30  		header := &doc.GenManHeader{
    31  			Title:   "COZY-STACK",
    32  			Section: "1",
    33  		}
    34  		return doc.GenManTree(RootCmd, header, args[0])
    35  	},
    36  }
    37  
    38  var markdownDocCmd = &cobra.Command{
    39  	Use:     "markdown <directory>",
    40  	Short:   "Print the documentation of cozy-stack as markdown",
    41  	Example: `$ cozy-stack doc markdown docs/cli`,
    42  	RunE: func(cmd *cobra.Command, args []string) error {
    43  		directory := "./docs/cli/"
    44  		if len(args) == 1 {
    45  			directory = args[0]
    46  		}
    47  		RootCmd.DisableAutoGenTag = true
    48  		return doc.GenMarkdownTree(RootCmd, directory)
    49  	},
    50  }
    51  
    52  func init() {
    53  	docCmdGroup.AddCommand(manDocCmd)
    54  	docCmdGroup.AddCommand(markdownDocCmd)
    55  	RootCmd.AddCommand(docCmdGroup)
    56  }