Files
mattermost/server/cmd/mmctl/commands/docs.go
Miguel de la Cruz 951456c780 Includes mmctl into the mono-repo (#23091)
* Includes mmctl into the mono-repo

* Update to use the new public module paths

* Adds docs check to the mmctl CI

* Fix public utils import path

* Tidy up modules

* Fix linter

* Update CI tasks to use the new file structure

* Update CI references
2023-06-05 12:42:55 +02:00

49 lines
982 B
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package commands
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)
var DocsCmd = &cobra.Command{
Use: "docs",
Short: "Generates mmctl documentation",
Args: cobra.NoArgs,
RunE: docsCmdF,
}
func init() {
DocsCmd.Flags().StringP("directory", "d", "docs", "The directory where the docs would be generated in.")
RootCmd.AddCommand(DocsCmd)
}
func docsCmdF(cmd *cobra.Command, args []string) error {
outDir, _ := cmd.Flags().GetString("directory")
fileInfo, err := os.Stat(outDir)
if err != nil {
if !os.IsNotExist(err) {
return err
}
if createErr := os.Mkdir(outDir, 0755); createErr != nil {
return createErr
}
} else if !fileInfo.IsDir() {
return fmt.Errorf(fmt.Sprintf("File \"%s\" is not a directory", outDir))
}
err = doc.GenReSTTree(RootCmd, outDir)
if err != nil {
return err
}
return nil
}