2018-09-13 07:29:26 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2020-11-05 11:33:32 +00:00
|
|
|
"context"
|
2018-09-13 07:29:26 +00:00
|
|
|
"fmt"
|
2018-09-24 20:28:10 +00:00
|
|
|
"log"
|
2018-09-13 07:29:26 +00:00
|
|
|
"os"
|
2018-09-24 20:28:10 +00:00
|
|
|
"regexp"
|
2022-06-22 14:56:41 +00:00
|
|
|
"sort"
|
2018-09-24 20:28:10 +00:00
|
|
|
"strings"
|
2018-09-13 07:29:26 +00:00
|
|
|
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/fs"
|
|
|
|
"github.com/rclone/rclone/fs/config/configflags"
|
2023-07-10 17:34:10 +00:00
|
|
|
"github.com/rclone/rclone/fs/config/flags"
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/fs/filter/filterflags"
|
2019-12-10 13:54:00 +00:00
|
|
|
"github.com/rclone/rclone/fs/log/logflags"
|
2023-03-23 12:04:17 +00:00
|
|
|
"github.com/rclone/rclone/fs/rc/rcflags"
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/lib/atexit"
|
2018-09-13 07:29:26 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/pflag"
|
2022-06-24 14:33:45 +00:00
|
|
|
"golang.org/x/text/cases"
|
|
|
|
"golang.org/x/text/language"
|
2018-09-13 07:29:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Root is the main rclone command
|
|
|
|
var Root = &cobra.Command{
|
|
|
|
Use: "rclone",
|
2018-09-24 20:28:10 +00:00
|
|
|
Short: "Show help for rclone commands, flags and backends.",
|
2018-09-13 07:29:26 +00: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 11:21:54 +00:00
|
|
|
BashCompletionFunction: bashCompletionFunc,
|
2019-06-20 15:18:02 +00:00
|
|
|
DisableAutoGenTag: true,
|
2018-09-13 07:29:26 +00:00
|
|
|
}
|
|
|
|
|
2019-02-06 11:21:54 +00:00
|
|
|
const (
|
|
|
|
bashCompletionFunc = `
|
2019-02-13 14:15:21 +00:00
|
|
|
__rclone_custom_func() {
|
2019-09-06 12:11:08 +00:00
|
|
|
if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
|
2019-02-06 11:21:54 +00: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 10:38:07 +00: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 20:59:09 +00:00
|
|
|
if [[ $cur != *:* ]]; then
|
2019-09-06 12:11:08 +00:00
|
|
|
local ifs=$IFS
|
|
|
|
IFS=$'\n'
|
2019-11-29 10:38:07 +00:00
|
|
|
local remotes=($("${rclone[@]}" listremotes 2> /dev/null))
|
2019-09-06 12:11:08 +00:00
|
|
|
IFS=$ifs
|
2019-02-06 11:21:54 +00:00
|
|
|
local remote
|
2019-09-06 12:11:08 +00:00
|
|
|
for remote in "${remotes[@]}"; do
|
2019-02-06 11:21:54 +00:00
|
|
|
[[ $remote != $cur* ]] || COMPREPLY+=("$remote")
|
2019-09-06 12:11:08 +00:00
|
|
|
done
|
2019-02-06 11:21:54 +00: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 20:59:09 +00:00
|
|
|
else
|
2019-02-06 11:21:54 +00:00
|
|
|
local path=${cur#*:}
|
|
|
|
if [[ $path == */* ]]; then
|
2019-03-17 10:15:20 +00:00
|
|
|
local prefix=$(eval printf '%s' "${path%/*}")
|
2019-02-06 11:21:54 +00:00
|
|
|
else
|
|
|
|
local prefix=
|
|
|
|
fi
|
2019-09-06 12:11:08 +00:00
|
|
|
local ifs=$IFS
|
|
|
|
IFS=$'\n'
|
2019-11-29 10:38:07 +00:00
|
|
|
local lines=($("${rclone[@]}" lsf "${cur%%:*}:$prefix" 2> /dev/null))
|
2019-09-06 12:11:08 +00:00
|
|
|
IFS=$ifs
|
2019-02-06 11:21:54 +00:00
|
|
|
local line
|
2019-09-06 12:11:08 +00:00
|
|
|
for line in "${lines[@]}"; do
|
2019-02-06 11:21:54 +00:00
|
|
|
local reply=${prefix:+$prefix/}$line
|
|
|
|
[[ $reply != $path* ]] || COMPREPLY+=("$reply")
|
2019-09-06 12:11:08 +00:00
|
|
|
done
|
2019-09-04 09:04:43 +00:00
|
|
|
[[ ! ${COMPREPLY[@]} || $(type -t compopt) != builtin ]] || compopt -o filenames
|
2019-02-06 11:21:54 +00:00
|
|
|
fi
|
2019-09-04 09:04:43 +00:00
|
|
|
[[ ! ${COMPREPLY[@]} || $(type -t compopt) != builtin ]] || compopt -o nospace
|
2019-02-06 11:21:54 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
`
|
|
|
|
)
|
|
|
|
|
2019-06-20 15:18:02 +00:00
|
|
|
// GeneratingDocs is set by rclone gendocs to alter the format of the
|
|
|
|
// output suitable for the documentation.
|
|
|
|
var GeneratingDocs = false
|
|
|
|
|
2018-09-13 07:29:26 +00:00
|
|
|
// root help command
|
|
|
|
var helpCommand = &cobra.Command{
|
|
|
|
Use: "help",
|
|
|
|
Short: Root.Short,
|
|
|
|
Long: Root.Long,
|
2018-09-24 20:28:10 +00:00
|
|
|
Run: func(command *cobra.Command, args []string) {
|
|
|
|
Root.SetOutput(os.Stdout)
|
|
|
|
_ = Root.Usage()
|
|
|
|
},
|
2018-09-13 07:29:26 +00:00
|
|
|
}
|
|
|
|
|
2018-09-24 20:28:10 +00:00
|
|
|
// to filter the flags with
|
|
|
|
var flagsRe *regexp.Regexp
|
|
|
|
|
2018-09-13 07:29:26 +00:00
|
|
|
// Show the flags
|
|
|
|
var helpFlags = &cobra.Command{
|
2018-09-24 20:28:10 +00:00
|
|
|
Use: "flags [<regexp to match>]",
|
2018-09-13 07:29:26 +00:00
|
|
|
Short: "Show the global flags for rclone",
|
|
|
|
Run: func(command *cobra.Command, args []string) {
|
2018-09-24 20:28:10 +00:00
|
|
|
if len(args) > 0 {
|
2023-07-10 17:34:10 +00:00
|
|
|
re, err := regexp.Compile(`(?i)` + args[0])
|
2018-09-24 20:28:10 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Failed to compile flags regexp: %v", err)
|
|
|
|
}
|
|
|
|
flagsRe = re
|
|
|
|
}
|
2019-06-20 15:18:02 +00:00
|
|
|
if GeneratingDocs {
|
|
|
|
Root.SetUsageTemplate(docFlagsTemplate)
|
|
|
|
} else {
|
|
|
|
Root.SetOutput(os.Stdout)
|
|
|
|
}
|
2018-09-13 07:29:26 +00:00
|
|
|
_ = command.Usage()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-09-24 20:28:10 +00: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 07:29:26 +00: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 20:42:45 +00:00
|
|
|
// Helpful example: https://github.com/moby/moby/blob/master/cli/cobra.go
|
2018-09-13 07:29:26 +00:00
|
|
|
func setupRootCommand(rootCmd *cobra.Command) {
|
2020-11-05 11:33:32 +00:00
|
|
|
ci := fs.GetConfig(context.Background())
|
2018-09-13 07:29:26 +00:00
|
|
|
// Add global flags
|
2020-11-05 11:33:32 +00:00
|
|
|
configflags.AddFlags(ci, pflag.CommandLine)
|
2018-09-13 07:29:26 +00:00
|
|
|
filterflags.AddFlags(pflag.CommandLine)
|
2023-03-23 12:04:17 +00:00
|
|
|
rcflags.AddFlags(pflag.CommandLine)
|
2019-12-10 13:54:00 +00:00
|
|
|
logflags.AddFlags(pflag.CommandLine)
|
2018-09-13 07:29:26 +00:00
|
|
|
|
|
|
|
Root.Run = runRoot
|
|
|
|
Root.Flags().BoolVarP(&version, "version", "V", false, "Print the version number")
|
|
|
|
|
|
|
|
cobra.AddTemplateFunc("showGlobalFlags", func(cmd *cobra.Command) bool {
|
2023-07-10 17:34:10 +00:00
|
|
|
return cmd.CalledAs() == "flags" || cmd.Annotations["groups"] != ""
|
2018-09-13 07:29:26 +00:00
|
|
|
})
|
|
|
|
cobra.AddTemplateFunc("showCommands", func(cmd *cobra.Command) bool {
|
|
|
|
return cmd.CalledAs() != "flags"
|
|
|
|
})
|
|
|
|
cobra.AddTemplateFunc("showLocalFlags", func(cmd *cobra.Command) bool {
|
2018-09-24 20:28:10 +00: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 07:29:26 +00:00
|
|
|
})
|
2023-07-10 17:34:10 +00:00
|
|
|
cobra.AddTemplateFunc("flagGroups", func(cmd *cobra.Command) []*flags.Group {
|
|
|
|
// Add the backend flags and check all flags
|
|
|
|
backendGroup := flags.All.NewGroup("Backend", "Backend only flags. These can be set in the config file also.")
|
|
|
|
allRegistered := flags.All.AllRegistered()
|
2018-09-13 07:30:16 +00:00
|
|
|
cmd.InheritedFlags().VisitAll(func(flag *pflag.Flag) {
|
2023-07-10 17:34:10 +00:00
|
|
|
if _, ok := backendFlags[flag.Name]; ok {
|
|
|
|
backendGroup.Add(flag)
|
|
|
|
} else if _, ok := allRegistered[flag]; ok {
|
|
|
|
// flag is in a group already
|
|
|
|
} else {
|
|
|
|
fs.Errorf(nil, "Flag --%s is unknown", flag.Name)
|
2018-09-13 07:30:16 +00:00
|
|
|
}
|
|
|
|
})
|
2023-07-10 17:34:10 +00:00
|
|
|
groups := flags.All.Filter(flagsRe).Include(cmd.Annotations["groups"])
|
|
|
|
return groups.Groups
|
2018-09-13 07:30:16 +00:00
|
|
|
})
|
2018-09-13 07:29:26 +00: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 20:28:10 +00:00
|
|
|
helpCommand.AddCommand(helpBackends)
|
|
|
|
helpCommand.AddCommand(helpBackend)
|
2018-09-13 07:29:26 +00: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}}
|
|
|
|
|
2023-07-10 17:34:10 +00:00
|
|
|
{{ range flagGroups . }}{{ if .Flags.HasFlags }}
|
|
|
|
# {{ .Name }} Flags
|
2018-09-13 07:30:16 +00:00
|
|
|
|
2023-07-10 17:34:10 +00:00
|
|
|
{{ .Help }}
|
|
|
|
|
|
|
|
{{ .Flags.FlagUsages | trimTrailingWhitespaces}}
|
|
|
|
{{ end }}{{ end }}
|
2018-09-13 07:29:26 +00:00
|
|
|
|
|
|
|
Additional help topics:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}}
|
|
|
|
{{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}
|
|
|
|
|
2018-09-24 20:28:10 +00:00
|
|
|
Use "rclone [command] --help" for more information about a command.
|
|
|
|
Use "rclone help flags" for to see the global flags.
|
2018-09-13 07:29:26 +00:00
|
|
|
Use "rclone help backends" for a list of supported services.
|
|
|
|
`
|
2018-09-24 20:28:10 +00:00
|
|
|
|
2019-06-20 15:18:02 +00:00
|
|
|
var docFlagsTemplate = `---
|
|
|
|
title: "Global Flags"
|
|
|
|
description: "Rclone Global Flags"
|
|
|
|
---
|
|
|
|
|
|
|
|
# Global Flags
|
|
|
|
|
|
|
|
This describes the global flags available to every rclone command
|
2023-07-10 17:34:10 +00:00
|
|
|
split into groups.
|
2019-06-20 15:18:02 +00:00
|
|
|
|
2023-07-10 17:34:10 +00:00
|
|
|
{{ range flagGroups . }}{{ if .Flags.HasFlags }}
|
|
|
|
## {{ .Name }}
|
2019-06-20 15:18:02 +00:00
|
|
|
|
2023-07-10 17:34:10 +00:00
|
|
|
{{ .Help }}
|
2019-06-20 15:18:02 +00:00
|
|
|
|
|
|
|
` + "```" + `
|
2023-07-10 17:34:10 +00:00
|
|
|
{{ .Flags.FlagUsages | trimTrailingWhitespaces}}
|
2019-06-20 15:18:02 +00:00
|
|
|
` + "```" + `
|
|
|
|
|
2023-07-10 17:34:10 +00:00
|
|
|
{{ end }}{{ end }}
|
2019-06-20 15:18:02 +00:00
|
|
|
`
|
|
|
|
|
2018-09-24 20:28:10 +00: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 21:49:58 +00:00
|
|
|
// Skip if done already (e.g. with Provider options)
|
2018-09-24 20:28:10 +00:00
|
|
|
if _, doneAlready := done[opt.Name]; doneAlready {
|
|
|
|
continue
|
|
|
|
}
|
2023-09-22 17:16:00 +00:00
|
|
|
done[opt.Name] = struct{}{}
|
2018-09-24 20:28:10 +00:00
|
|
|
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 08:54:50 +00:00
|
|
|
optionsType = "advanced"
|
2018-09-24 20:28:10 +00:00
|
|
|
continue
|
|
|
|
}
|
2022-06-24 14:33:45 +00:00
|
|
|
optionsType = cases.Title(language.Und, cases.NoLower).String(optionsType)
|
|
|
|
fmt.Printf("### %s options\n\n", optionsType)
|
2018-09-24 20:28:10 +00: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 17:24:05 +00: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 20:28:10 +00:00
|
|
|
fmt.Printf("%s\n\n", opt.Help)
|
2020-05-31 11:57:28 +00:00
|
|
|
if opt.IsPassword {
|
|
|
|
fmt.Printf("**NB** Input to this must be obscured - see [rclone obscure](/commands/rclone_obscure/).\n\n")
|
|
|
|
}
|
2022-01-24 14:28:53 +00:00
|
|
|
fmt.Printf("Properties:\n\n")
|
2018-09-24 20:28:10 +00:00
|
|
|
fmt.Printf("- Config: %s\n", opt.Name)
|
|
|
|
fmt.Printf("- Env Var: %s\n", opt.EnvVarName(backend.Prefix))
|
2022-01-24 14:28:53 +00:00
|
|
|
if opt.Provider != "" {
|
|
|
|
fmt.Printf("- Provider: %s\n", opt.Provider)
|
|
|
|
}
|
2018-09-24 20:28:10 +00:00
|
|
|
fmt.Printf("- Type: %s\n", opt.Type())
|
2022-01-24 14:28:53 +00: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 02:56:32 +00:00
|
|
|
// to be explicitly set and then Required makes no difference.
|
2022-01-24 14:28:53 +00: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 20:28:10 +00:00
|
|
|
if len(opt.Examples) > 0 {
|
2022-01-24 14:28:53 +00:00
|
|
|
if opt.Exclusive {
|
|
|
|
fmt.Printf("- Choices:\n")
|
|
|
|
} else {
|
|
|
|
fmt.Printf("- Examples:\n")
|
|
|
|
}
|
2018-09-24 20:28:10 +00: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 14:56:41 +00: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 20:28:10 +00:00
|
|
|
}
|