Add gendocs command to rclone
This commit is contained in:
parent
2df261e42b
commit
ba0b41dd92
1 changed files with 41 additions and 1 deletions
42
rclone.go
42
rclone.go
|
@ -11,12 +11,15 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/cobra/doc"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
"github.com/ncw/rclone/fs"
|
"github.com/ncw/rclone/fs"
|
||||||
|
@ -82,7 +85,7 @@ func init() {
|
||||||
rootCmd.AddCommand(copyCmd, syncCmd, moveCmd, lsCmd, lsdCmd,
|
rootCmd.AddCommand(copyCmd, syncCmd, moveCmd, lsCmd, lsdCmd,
|
||||||
lslCmd, md5sumCmd, sha1sumCmd, sizeCmd, mkdirCmd,
|
lslCmd, md5sumCmd, sha1sumCmd, sizeCmd, mkdirCmd,
|
||||||
rmdirCmd, purgeCmd, deleteCmd, checkCmd, dedupeCmd,
|
rmdirCmd, purgeCmd, deleteCmd, checkCmd, dedupeCmd,
|
||||||
genautocompleteCmd, configCmd, authorizeCmd,
|
genautocompleteCmd, gendocsCmd, configCmd, authorizeCmd,
|
||||||
cleanupCmd, memtestCmd, versionCmd)
|
cleanupCmd, memtestCmd, versionCmd)
|
||||||
dedupeCmd.Flags().VarP(&dedupeMode, "dedupe-mode", "", "Dedupe mode interactive|skip|first|newest|oldest|rename.")
|
dedupeCmd.Flags().VarP(&dedupeMode, "dedupe-mode", "", "Dedupe mode interactive|skip|first|newest|oldest|rename.")
|
||||||
cobra.OnInitialize(initConfig)
|
cobra.OnInitialize(initConfig)
|
||||||
|
@ -512,6 +515,43 @@ there.
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const gendocFrontmatterTemplate = `---
|
||||||
|
date: %s
|
||||||
|
title: "%s"
|
||||||
|
slug: %s
|
||||||
|
url: %s
|
||||||
|
---
|
||||||
|
`
|
||||||
|
|
||||||
|
var gendocsCmd = &cobra.Command{
|
||||||
|
Use: "gendocs output_directory",
|
||||||
|
Short: `Output markdown docs for rclone to the directory supplied.`,
|
||||||
|
Long: `
|
||||||
|
This produces markdown docs for the rclone commands to the directory
|
||||||
|
supplied. These are in a format suitable for hugo to render into the
|
||||||
|
rclone.org website.`,
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
checkArgs(1, 1, cmd, args)
|
||||||
|
out := args[0]
|
||||||
|
err := os.MkdirAll(out, 0777)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
now := time.Now().Format(time.RFC3339)
|
||||||
|
prepender := func(filename string) string {
|
||||||
|
name := filepath.Base(filename)
|
||||||
|
base := strings.TrimSuffix(name, path.Ext(name))
|
||||||
|
url := "/commands/" + strings.ToLower(base) + "/"
|
||||||
|
return fmt.Sprintf(gendocFrontmatterTemplate, now, strings.Replace(base, "_", " ", -1), base, url)
|
||||||
|
}
|
||||||
|
linkHandler := func(name string) string {
|
||||||
|
base := strings.TrimSuffix(name, path.Ext(name))
|
||||||
|
return "/commands/" + strings.ToLower(base) + "/"
|
||||||
|
}
|
||||||
|
return doc.GenMarkdownTreeCustom(rootCmd, out, prepender, linkHandler)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
var authorizeCmd = &cobra.Command{
|
var authorizeCmd = &cobra.Command{
|
||||||
Use: "authorize",
|
Use: "authorize",
|
||||||
Short: `Remote authorization.`,
|
Short: `Remote authorization.`,
|
||||||
|
|
Loading…
Add table
Reference in a new issue