2024-01-01 10:31:45 +00:00
|
|
|
// Copyright (C) 2019 Nicola Murino
|
2022-07-17 18:16:00 +00:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published
|
|
|
|
// by the Free Software Foundation, version 3.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
2023-01-03 09:18:30 +00:00
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2022-07-17 18:16:00 +00:00
|
|
|
|
2020-07-08 21:21:33 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2022-05-09 17:09:43 +00:00
|
|
|
"errors"
|
2020-07-08 21:21:33 +00:00
|
|
|
"fmt"
|
2022-05-09 17:09:43 +00:00
|
|
|
"io/fs"
|
2020-07-08 21:21:33 +00:00
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/rs/zerolog"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/cobra/doc"
|
|
|
|
|
2022-07-24 14:18:54 +00:00
|
|
|
"github.com/drakkan/sftpgo/v2/internal/logger"
|
|
|
|
"github.com/drakkan/sftpgo/v2/internal/version"
|
2020-07-08 21:21:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
manDir string
|
|
|
|
genManCmd = &cobra.Command{
|
|
|
|
Use: "man",
|
2021-10-03 06:14:57 +00:00
|
|
|
Short: "Generate man pages for sftpgo",
|
2020-07-08 21:21:33 +00:00
|
|
|
Long: `This command automatically generates up-to-date man pages of SFTPGo's
|
2021-10-03 06:14:57 +00:00
|
|
|
command-line interface.
|
|
|
|
By default, it creates the man page files in the "man" directory under the
|
|
|
|
current directory.
|
2020-07-08 21:21:33 +00:00
|
|
|
`,
|
2022-07-19 21:28:33 +00:00
|
|
|
Run: func(cmd *cobra.Command, _ []string) {
|
2020-07-08 21:21:33 +00:00
|
|
|
logger.DisableLogger()
|
|
|
|
logger.EnableConsoleLogger(zerolog.DebugLevel)
|
2022-05-09 17:09:43 +00:00
|
|
|
if _, err := os.Stat(manDir); errors.Is(err, fs.ErrNotExist) {
|
2020-07-10 17:20:37 +00:00
|
|
|
err = os.MkdirAll(manDir, os.ModePerm)
|
2020-07-08 21:21:33 +00:00
|
|
|
if err != nil {
|
|
|
|
logger.WarnToConsole("Unable to generate man page files: %v", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
header := &doc.GenManHeader{
|
|
|
|
Section: "1",
|
|
|
|
Manual: "SFTPGo Manual",
|
|
|
|
Source: fmt.Sprintf("SFTPGo %v", version.Get().Version),
|
|
|
|
}
|
|
|
|
cmd.Root().DisableAutoGenTag = true
|
|
|
|
err := doc.GenManTree(cmd.Root(), header, manDir)
|
|
|
|
if err != nil {
|
|
|
|
logger.WarnToConsole("Unable to generate man page files: %v", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
genManCmd.Flags().StringVarP(&manDir, "dir", "d", "man", "The directory to write the man pages")
|
|
|
|
genCmd.AddCommand(genManCmd)
|
|
|
|
}
|