2018-09-13 09:29:26 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2020-11-05 12:33:32 +01:00
|
|
|
"context"
|
2018-09-13 09:29:26 +02:00
|
|
|
"fmt"
|
2018-09-24 22:28:10 +02:00
|
|
|
"log"
|
2018-09-13 09:29:26 +02:00
|
|
|
"os"
|
2018-09-24 22:28:10 +02:00
|
|
|
"regexp"
|
2022-06-22 16:56:41 +02:00
|
|
|
"sort"
|
2018-09-24 22:28:10 +02:00
|
|
|
"strings"
|
2018-09-13 09:29:26 +02:00
|
|
|
|
2019-07-28 19:47:38 +02:00
|
|
|
"github.com/rclone/rclone/fs"
|
|
|
|
"github.com/rclone/rclone/fs/config/configflags"
|
|
|
|
"github.com/rclone/rclone/fs/filter/filterflags"
|
2019-12-10 14:54:00 +01:00
|
|
|
"github.com/rclone/rclone/fs/log/logflags"
|
2019-07-28 19:47:38 +02:00
|
|
|
"github.com/rclone/rclone/lib/atexit"
|
2018-09-13 09:29:26 +02:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/pflag"
|
2022-06-24 16:33:45 +02:00
|
|
|
"golang.org/x/text/cases"
|
|
|
|
"golang.org/x/text/language"
|
2018-09-13 09:29:26 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Root is the main rclone command
|
|
|
|
var Root = &cobra.Command{
|
|
|
|
Use: "rclone",
|
2018-09-24 22:28:10 +02:00
|
|
|
Short: "Show help for rclone commands, flags and backends.",
|
2018-09-13 09:29:26 +02:00
|
|
|
Long: `
|
|
|
|
Rclone syncs files to and from cloud storage providers as well as
|
|
|
|
mounting them, listing them in lots of different ways.
|
|
|
|
|
|
|
|
See the home page (https://rclone.org/) for installation, usage,
|
|
|
|
documentation, changelog and configuration walkthroughs.
|
|
|
|
|
|
|
|
`,
|
|
|
|
PersistentPostRun: func(cmd *cobra.Command, args []string) {
|
|
|
|
fs.Debugf("rclone", "Version %q finishing with parameters %q", fs.Version, os.Args)
|
|
|
|
atexit.Run()
|
|
|
|
},
|
2019-02-06 12:21:54 +01:00
|
|
|
BashCompletionFunction: bashCompletionFunc,
|
2019-06-20 17:18:02 +02:00
|
|
|
DisableAutoGenTag: true,
|
2018-09-13 09:29:26 +02:00
|
|
|
}
|
|
|
|
|
2019-02-06 12:21:54 +01:00
|
|
|
const (
|
|
|
|
bashCompletionFunc = `
|
2019-02-13 15:15:21 +01:00
|
|
|
__rclone_custom_func() {
|
2019-09-06 14:11:08 +02:00
|
|
|
if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
|
2019-02-06 12:21:54 +01:00
|
|
|
local cur cword prev words
|
|
|
|
if declare -F _init_completion > /dev/null; then
|
|
|
|
_init_completion -n : || return
|
|
|
|
else
|
|
|
|
__rclone_init_completion -n : || return
|
|
|
|
fi
|
2019-11-29 11:38:07 +01:00
|
|
|
local rclone=(command rclone --ask-password=false)
|
cmd: fix completion of remotes
The previous behavior of the remotes completion was that only
alphanumeric characters were allowed in a remote name. This limitation
has been lifted somewhat by #2985, which also allowed an underscore.
With the new implementation introduced in this commit, the completion of
the remote name has been simplified: If there is no colon (":") in the
current word, then complete remote name. Otherwise, complete the path
inside the specified remote. This allows correct completion of all
remote names that are allowed by the config (including - and _).
Actually it matches much more than that, even remote names that are not
allowed by the config, but in such a case there already would be a wrong
identifier in the configuration file.
With this simpler string comparison, we can get rid of the regular
expression, which makes the completion multiple times faster. For a
sample benchmark, try the following:
# Old way
$ time bash -c 'for _ in {1..1000000}; do
[[ remote:path =~ ^[[:alnum:]]*$ ]]; done'
real 0m15,637s
user 0m15,613s
sys 0m0,024s
# New way
$ time bash -c 'for _ in {1..1000000}; do
[[ remote:path != *:* ]]; done'
real 0m1,324s
user 0m1,304s
sys 0m0,020s
2019-03-14 21:59:09 +01:00
|
|
|
if [[ $cur != *:* ]]; then
|
2019-09-06 14:11:08 +02:00
|
|
|
local ifs=$IFS
|
|
|
|
IFS=$'\n'
|
2019-11-29 11:38:07 +01:00
|
|
|
local remotes=($("${rclone[@]}" listremotes 2> /dev/null))
|
2019-09-06 14:11:08 +02:00
|
|
|
IFS=$ifs
|
2019-02-06 12:21:54 +01:00
|
|
|
local remote
|
2019-09-06 14:11:08 +02:00
|
|
|
for remote in "${remotes[@]}"; do
|
2019-02-06 12:21:54 +01:00
|
|
|
[[ $remote != $cur* ]] || COMPREPLY+=("$remote")
|
2019-09-06 14:11:08 +02:00
|
|
|
done
|
2019-02-06 12:21:54 +01:00
|
|
|
if [[ ${COMPREPLY[@]} ]]; then
|
|
|
|
local paths=("$cur"*)
|
|
|
|
[[ ! -f ${paths[0]} ]] || COMPREPLY+=("${paths[@]}")
|
|
|
|
fi
|
cmd: fix completion of remotes
The previous behavior of the remotes completion was that only
alphanumeric characters were allowed in a remote name. This limitation
has been lifted somewhat by #2985, which also allowed an underscore.
With the new implementation introduced in this commit, the completion of
the remote name has been simplified: If there is no colon (":") in the
current word, then complete remote name. Otherwise, complete the path
inside the specified remote. This allows correct completion of all
remote names that are allowed by the config (including - and _).
Actually it matches much more than that, even remote names that are not
allowed by the config, but in such a case there already would be a wrong
identifier in the configuration file.
With this simpler string comparison, we can get rid of the regular
expression, which makes the completion multiple times faster. For a
sample benchmark, try the following:
# Old way
$ time bash -c 'for _ in {1..1000000}; do
[[ remote:path =~ ^[[:alnum:]]*$ ]]; done'
real 0m15,637s
user 0m15,613s
sys 0m0,024s
# New way
$ time bash -c 'for _ in {1..1000000}; do
[[ remote:path != *:* ]]; done'
real 0m1,324s
user 0m1,304s
sys 0m0,020s
2019-03-14 21:59:09 +01:00
|
|
|
else
|
2019-02-06 12:21:54 +01:00
|
|
|
local path=${cur#*:}
|
|
|
|
if [[ $path == */* ]]; then
|
2019-03-17 11:15:20 +01:00
|
|
|
local prefix=$(eval printf '%s' "${path%/*}")
|
2019-02-06 12:21:54 +01:00
|
|
|
else
|
|
|
|
local prefix=
|
|
|
|
fi
|
2019-09-06 14:11:08 +02:00
|
|
|
local ifs=$IFS
|
|
|
|
IFS=$'\n'
|
2019-11-29 11:38:07 +01:00
|
|
|
local lines=($("${rclone[@]}" lsf "${cur%%:*}:$prefix" 2> /dev/null))
|
2019-09-06 14:11:08 +02:00
|
|
|
IFS=$ifs
|
2019-02-06 12:21:54 +01:00
|
|
|
local line
|
2019-09-06 14:11:08 +02:00
|
|
|
for line in "${lines[@]}"; do
|
2019-02-06 12:21:54 +01:00
|
|
|
local reply=${prefix:+$prefix/}$line
|
|
|
|
[[ $reply != $path* ]] || COMPREPLY+=("$reply")
|
2019-09-06 14:11:08 +02:00
|
|
|
done
|
2019-09-04 11:04:43 +02:00
|
|
|
[[ ! ${COMPREPLY[@]} || $(type -t compopt) != builtin ]] || compopt -o filenames
|
2019-02-06 12:21:54 +01:00
|
|
|
fi
|
2019-09-04 11:04:43 +02:00
|
|
|
[[ ! ${COMPREPLY[@]} || $(type -t compopt) != builtin ]] || compopt -o nospace
|
2019-02-06 12:21:54 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
`
|
|
|
|
)
|
|
|
|
|
2019-06-20 17:18:02 +02:00
|
|
|
// GeneratingDocs is set by rclone gendocs to alter the format of the
|
|
|
|
// output suitable for the documentation.
|
|
|
|
var GeneratingDocs = false
|
|
|
|
|
2018-09-13 09:29:26 +02:00
|
|
|
// root help command
|
|
|
|
var helpCommand = &cobra.Command{
|
|
|
|
Use: "help",
|
|
|
|
Short: Root.Short,
|
|
|
|
Long: Root.Long,
|
2018-09-24 22:28:10 +02:00
|
|
|
Run: func(command *cobra.Command, args []string) {
|
|
|
|
Root.SetOutput(os.Stdout)
|
|
|
|
_ = Root.Usage()
|
|
|
|
},
|
2018-09-13 09:29:26 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 22:28:10 +02:00
|
|
|
// to filter the flags with
|
|
|
|
var flagsRe *regexp.Regexp
|
|
|
|
|
2018-09-13 09:29:26 +02:00
|
|
|
// Show the flags
|
|
|
|
var helpFlags = &cobra.Command{
|
2018-09-24 22:28:10 +02:00
|
|
|
Use: "flags [<regexp to match>]",
|
2018-09-13 09:29:26 +02:00
|
|
|
Short: "Show the global flags for rclone",
|
|
|
|
Run: func(command *cobra.Command, args []string) {
|
2018-09-24 22:28:10 +02:00
|
|
|
if len(args) > 0 {
|
|
|
|
re, err := regexp.Compile(args[0])
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Failed to compile flags regexp: %v", err)
|
|
|
|
}
|
|
|
|
flagsRe = re
|
|
|
|
}
|
2019-06-20 17:18:02 +02:00
|
|
|
if GeneratingDocs {
|
|
|
|
Root.SetUsageTemplate(docFlagsTemplate)
|
|
|
|
} else {
|
|
|
|
Root.SetOutput(os.Stdout)
|
|
|
|
}
|
2018-09-13 09:29:26 +02:00
|
|
|
_ = command.Usage()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-09-24 22:28:10 +02:00
|
|
|
// Show the backends
|
|
|
|
var helpBackends = &cobra.Command{
|
|
|
|
Use: "backends",
|
|
|
|
Short: "List the backends available",
|
|
|
|
Run: func(command *cobra.Command, args []string) {
|
|
|
|
showBackends()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show a single backend
|
|
|
|
var helpBackend = &cobra.Command{
|
|
|
|
Use: "backend <name>",
|
|
|
|
Short: "List full info about a backend",
|
|
|
|
Run: func(command *cobra.Command, args []string) {
|
|
|
|
if len(args) == 0 {
|
|
|
|
Root.SetOutput(os.Stdout)
|
|
|
|
_ = command.Usage()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
showBackend(args[0])
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-09-13 09:29:26 +02:00
|
|
|
// runRoot implements the main rclone command with no subcommands
|
|
|
|
func runRoot(cmd *cobra.Command, args []string) {
|
|
|
|
if version {
|
|
|
|
ShowVersion()
|
|
|
|
resolveExitCode(nil)
|
|
|
|
} else {
|
|
|
|
_ = cmd.Usage()
|
|
|
|
if len(args) > 0 {
|
|
|
|
_, _ = fmt.Fprintf(os.Stderr, "Command not found.\n")
|
|
|
|
}
|
|
|
|
resolveExitCode(errorCommandNotFound)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// setupRootCommand sets default usage, help, and error handling for
|
|
|
|
// the root command.
|
|
|
|
//
|
2021-12-20 21:42:45 +01:00
|
|
|
// Helpful example: https://github.com/moby/moby/blob/master/cli/cobra.go
|
2018-09-13 09:29:26 +02:00
|
|
|
func setupRootCommand(rootCmd *cobra.Command) {
|
2020-11-05 12:33:32 +01:00
|
|
|
ci := fs.GetConfig(context.Background())
|
2018-09-13 09:29:26 +02:00
|
|
|
// Add global flags
|
2020-11-05 12:33:32 +01:00
|
|
|
configflags.AddFlags(ci, pflag.CommandLine)
|
2018-09-13 09:29:26 +02:00
|
|
|
filterflags.AddFlags(pflag.CommandLine)
|
2019-12-10 14:54:00 +01:00
|
|
|
logflags.AddFlags(pflag.CommandLine)
|
2018-09-13 09:29:26 +02:00
|
|
|
|
|
|
|
Root.Run = runRoot
|
|
|
|
Root.Flags().BoolVarP(&version, "version", "V", false, "Print the version number")
|
|
|
|
|
|
|
|
cobra.AddTemplateFunc("showGlobalFlags", func(cmd *cobra.Command) bool {
|
|
|
|
return cmd.CalledAs() == "flags"
|
|
|
|
})
|
|
|
|
cobra.AddTemplateFunc("showCommands", func(cmd *cobra.Command) bool {
|
|
|
|
return cmd.CalledAs() != "flags"
|
|
|
|
})
|
|
|
|
cobra.AddTemplateFunc("showLocalFlags", func(cmd *cobra.Command) bool {
|
2018-09-24 22:28:10 +02:00
|
|
|
// Don't show local flags (which are the global ones on the root) on "rclone" and
|
|
|
|
// "rclone help" (which shows the global help)
|
|
|
|
return cmd.CalledAs() != "rclone" && cmd.CalledAs() != ""
|
2018-09-13 09:29:26 +02:00
|
|
|
})
|
2018-09-13 09:30:16 +02:00
|
|
|
cobra.AddTemplateFunc("backendFlags", func(cmd *cobra.Command, include bool) *pflag.FlagSet {
|
|
|
|
backendFlagSet := pflag.NewFlagSet("Backend Flags", pflag.ExitOnError)
|
|
|
|
cmd.InheritedFlags().VisitAll(func(flag *pflag.Flag) {
|
2018-09-24 22:28:10 +02:00
|
|
|
matched := flagsRe == nil || flagsRe.MatchString(flag.Name)
|
|
|
|
if _, ok := backendFlags[flag.Name]; matched && ok == include {
|
2018-09-13 09:30:16 +02:00
|
|
|
backendFlagSet.AddFlag(flag)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return backendFlagSet
|
|
|
|
})
|
2018-09-13 09:29:26 +02:00
|
|
|
rootCmd.SetUsageTemplate(usageTemplate)
|
|
|
|
// rootCmd.SetHelpTemplate(helpTemplate)
|
|
|
|
// rootCmd.SetFlagErrorFunc(FlagErrorFunc)
|
|
|
|
rootCmd.SetHelpCommand(helpCommand)
|
|
|
|
// rootCmd.PersistentFlags().BoolP("help", "h", false, "Print usage")
|
|
|
|
// rootCmd.PersistentFlags().MarkShorthandDeprecated("help", "please use --help")
|
|
|
|
|
|
|
|
rootCmd.AddCommand(helpCommand)
|
|
|
|
helpCommand.AddCommand(helpFlags)
|
2018-09-24 22:28:10 +02:00
|
|
|
helpCommand.AddCommand(helpBackends)
|
|
|
|
helpCommand.AddCommand(helpBackend)
|
2018-09-13 09:29:26 +02:00
|
|
|
|
|
|
|
cobra.OnInitialize(initConfig)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var usageTemplate = `Usage:{{if .Runnable}}
|
|
|
|
{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
|
|
|
|
{{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}}
|
|
|
|
|
|
|
|
Aliases:
|
|
|
|
{{.NameAndAliases}}{{end}}{{if .HasExample}}
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
{{.Example}}{{end}}{{if and (showCommands .) .HasAvailableSubCommands}}
|
|
|
|
|
|
|
|
Available Commands:{{range .Commands}}{{if (or .IsAvailableCommand (eq .Name "help"))}}
|
|
|
|
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if and (showLocalFlags .) .HasAvailableLocalFlags}}
|
|
|
|
|
|
|
|
Flags:
|
|
|
|
{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if and (showGlobalFlags .) .HasAvailableInheritedFlags}}
|
|
|
|
|
|
|
|
Global Flags:
|
2018-09-13 09:30:16 +02:00
|
|
|
{{(backendFlags . false).FlagUsages | trimTrailingWhitespaces}}
|
|
|
|
|
|
|
|
Backend Flags:
|
|
|
|
{{(backendFlags . true).FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasHelpSubCommands}}
|
2018-09-13 09:29:26 +02:00
|
|
|
|
|
|
|
Additional help topics:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}}
|
|
|
|
{{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}
|
|
|
|
|
2018-09-24 22:28:10 +02:00
|
|
|
Use "rclone [command] --help" for more information about a command.
|
|
|
|
Use "rclone help flags" for to see the global flags.
|
2018-09-13 09:29:26 +02:00
|
|
|
Use "rclone help backends" for a list of supported services.
|
|
|
|
`
|
2018-09-24 22:28:10 +02:00
|
|
|
|
2019-06-20 17:18:02 +02:00
|
|
|
var docFlagsTemplate = `---
|
|
|
|
title: "Global Flags"
|
|
|
|
description: "Rclone Global Flags"
|
|
|
|
---
|
|
|
|
|
|
|
|
# Global Flags
|
|
|
|
|
|
|
|
This describes the global flags available to every rclone command
|
|
|
|
split into two groups, non backend and backend flags.
|
|
|
|
|
|
|
|
## Non Backend Flags
|
|
|
|
|
|
|
|
These flags are available for every command.
|
|
|
|
|
|
|
|
` + "```" + `
|
|
|
|
{{(backendFlags . false).FlagUsages | trimTrailingWhitespaces}}
|
|
|
|
` + "```" + `
|
|
|
|
|
|
|
|
## Backend Flags
|
|
|
|
|
|
|
|
These flags are available for every command. They control the backends
|
|
|
|
and may be set in the config file.
|
|
|
|
|
|
|
|
` + "```" + `
|
|
|
|
{{(backendFlags . true).FlagUsages | trimTrailingWhitespaces}}
|
|
|
|
` + "```" + `
|
|
|
|
`
|
|
|
|
|
2018-09-24 22:28:10 +02:00
|
|
|
// show all the backends
|
|
|
|
func showBackends() {
|
|
|
|
fmt.Printf("All rclone backends:\n\n")
|
|
|
|
for _, backend := range fs.Registry {
|
|
|
|
fmt.Printf(" %-12s %s\n", backend.Prefix, backend.Description)
|
|
|
|
}
|
|
|
|
fmt.Printf("\nTo see more info about a particular backend use:\n")
|
|
|
|
fmt.Printf(" rclone help backend <name>\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
func quoteString(v interface{}) string {
|
|
|
|
switch v.(type) {
|
|
|
|
case string:
|
|
|
|
return fmt.Sprintf("%q", v)
|
|
|
|
}
|
|
|
|
return fmt.Sprint(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
// show a single backend
|
|
|
|
func showBackend(name string) {
|
|
|
|
backend, err := fs.Find(name)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
var standardOptions, advancedOptions fs.Options
|
|
|
|
done := map[string]struct{}{}
|
|
|
|
for _, opt := range backend.Options {
|
2020-10-13 23:49:58 +02:00
|
|
|
// Skip if done already (e.g. with Provider options)
|
2018-09-24 22:28:10 +02:00
|
|
|
if _, doneAlready := done[opt.Name]; doneAlready {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if opt.Advanced {
|
|
|
|
advancedOptions = append(advancedOptions, opt)
|
|
|
|
} else {
|
|
|
|
standardOptions = append(standardOptions, opt)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
optionsType := "standard"
|
|
|
|
for _, opts := range []fs.Options{standardOptions, advancedOptions} {
|
|
|
|
if len(opts) == 0 {
|
2019-08-15 10:54:50 +02:00
|
|
|
optionsType = "advanced"
|
2018-09-24 22:28:10 +02:00
|
|
|
continue
|
|
|
|
}
|
2022-06-24 16:33:45 +02:00
|
|
|
optionsType = cases.Title(language.Und, cases.NoLower).String(optionsType)
|
|
|
|
fmt.Printf("### %s options\n\n", optionsType)
|
2018-09-24 22:28:10 +02:00
|
|
|
fmt.Printf("Here are the %s options specific to %s (%s).\n\n", optionsType, backend.Name, backend.Description)
|
|
|
|
optionsType = "advanced"
|
|
|
|
for _, opt := range opts {
|
|
|
|
done[opt.Name] = struct{}{}
|
2019-09-14 19:24:05 +02:00
|
|
|
shortOpt := ""
|
|
|
|
if opt.ShortOpt != "" {
|
|
|
|
shortOpt = fmt.Sprintf(" / -%s", opt.ShortOpt)
|
|
|
|
}
|
|
|
|
fmt.Printf("#### --%s%s\n\n", opt.FlagName(backend.Prefix), shortOpt)
|
2018-09-24 22:28:10 +02:00
|
|
|
fmt.Printf("%s\n\n", opt.Help)
|
2020-05-31 13:57:28 +02:00
|
|
|
if opt.IsPassword {
|
|
|
|
fmt.Printf("**NB** Input to this must be obscured - see [rclone obscure](/commands/rclone_obscure/).\n\n")
|
|
|
|
}
|
2022-01-24 15:28:53 +01:00
|
|
|
fmt.Printf("Properties:\n\n")
|
2018-09-24 22:28:10 +02:00
|
|
|
fmt.Printf("- Config: %s\n", opt.Name)
|
|
|
|
fmt.Printf("- Env Var: %s\n", opt.EnvVarName(backend.Prefix))
|
2022-01-24 15:28:53 +01:00
|
|
|
if opt.Provider != "" {
|
|
|
|
fmt.Printf("- Provider: %s\n", opt.Provider)
|
|
|
|
}
|
2018-09-24 22:28:10 +02:00
|
|
|
fmt.Printf("- Type: %s\n", opt.Type())
|
2022-01-24 15:28:53 +01:00
|
|
|
defaultValue := opt.GetValue()
|
|
|
|
// Default value and Required are related: Required means option must
|
|
|
|
// have a value, but if there is a default then a value does not have
|
2022-08-14 04:56:32 +02:00
|
|
|
// to be explicitly set and then Required makes no difference.
|
2022-01-24 15:28:53 +01:00
|
|
|
if defaultValue != "" {
|
|
|
|
fmt.Printf("- Default: %s\n", quoteString(defaultValue))
|
|
|
|
} else {
|
|
|
|
fmt.Printf("- Required: %v\n", opt.Required)
|
|
|
|
}
|
|
|
|
// List examples / possible choices
|
2018-09-24 22:28:10 +02:00
|
|
|
if len(opt.Examples) > 0 {
|
2022-01-24 15:28:53 +01:00
|
|
|
if opt.Exclusive {
|
|
|
|
fmt.Printf("- Choices:\n")
|
|
|
|
} else {
|
|
|
|
fmt.Printf("- Examples:\n")
|
|
|
|
}
|
2018-09-24 22:28:10 +02:00
|
|
|
for _, ex := range opt.Examples {
|
|
|
|
fmt.Printf(" - %s\n", quoteString(ex.Value))
|
|
|
|
for _, line := range strings.Split(ex.Help, "\n") {
|
|
|
|
fmt.Printf(" - %s\n", line)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Printf("\n")
|
|
|
|
}
|
|
|
|
}
|
2022-06-22 16:56:41 +02:00
|
|
|
if backend.MetadataInfo != nil {
|
|
|
|
fmt.Printf("### Metadata\n\n")
|
|
|
|
fmt.Printf("%s\n\n", strings.TrimSpace(backend.MetadataInfo.Help))
|
|
|
|
if len(backend.MetadataInfo.System) > 0 {
|
|
|
|
fmt.Printf("Here are the possible system metadata items for the %s backend.\n\n", backend.Name)
|
|
|
|
keys := []string{}
|
|
|
|
for k := range backend.MetadataInfo.System {
|
|
|
|
keys = append(keys, k)
|
|
|
|
}
|
|
|
|
sort.Strings(keys)
|
|
|
|
fmt.Printf("| Name | Help | Type | Example | Read Only |\n")
|
|
|
|
fmt.Printf("|------|------|------|---------|-----------|\n")
|
|
|
|
for _, k := range keys {
|
|
|
|
v := backend.MetadataInfo.System[k]
|
|
|
|
ro := "N"
|
|
|
|
if v.ReadOnly {
|
|
|
|
ro = "**Y**"
|
|
|
|
}
|
|
|
|
fmt.Printf("| %s | %s | %s | %s | %s |\n", k, v.Help, v.Type, v.Example, ro)
|
|
|
|
}
|
|
|
|
fmt.Printf("\n")
|
|
|
|
}
|
|
|
|
fmt.Printf("See the [metadata](/docs/#metadata) docs for more info.\n\n")
|
|
|
|
}
|
2018-09-24 22:28:10 +02:00
|
|
|
}
|