mirror of
https://github.com/rclone/rclone
synced 2024-12-22 13:03:02 +01:00
cmd: split flags up into global and backend flags #2541
This commit is contained in:
parent
3c086f5f7f
commit
5fde7d8b12
@ -432,8 +432,11 @@ func resolveExitCode(err error) {
|
||||
}
|
||||
}
|
||||
|
||||
var backendFlags map[string]struct{}
|
||||
|
||||
// AddBackendFlags creates flags for all the backend options
|
||||
func AddBackendFlags() {
|
||||
backendFlags = map[string]struct{}{}
|
||||
for _, fsInfo := range fs.Registry {
|
||||
done := map[string]struct{}{}
|
||||
for i := range fsInfo.Options {
|
||||
@ -464,6 +467,7 @@ func AddBackendFlags() {
|
||||
if opt.Hide&fs.OptionHideCommandLine != 0 {
|
||||
flag.Hidden = true
|
||||
}
|
||||
backendFlags[name] = struct{}{}
|
||||
} else {
|
||||
fs.Errorf(nil, "Not adding duplicate flag --%s", name)
|
||||
}
|
||||
|
14
cmd/help.go
14
cmd/help.go
@ -83,6 +83,15 @@ func setupRootCommand(rootCmd *cobra.Command) {
|
||||
cobra.AddTemplateFunc("showLocalFlags", func(cmd *cobra.Command) bool {
|
||||
return cmd.CalledAs() != "rclone"
|
||||
})
|
||||
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) {
|
||||
if _, ok := backendFlags[flag.Name]; ok == include {
|
||||
backendFlagSet.AddFlag(flag)
|
||||
}
|
||||
})
|
||||
return backendFlagSet
|
||||
})
|
||||
rootCmd.SetUsageTemplate(usageTemplate)
|
||||
// rootCmd.SetHelpTemplate(helpTemplate)
|
||||
// rootCmd.SetFlagErrorFunc(FlagErrorFunc)
|
||||
@ -116,7 +125,10 @@ Flags:
|
||||
{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if and (showGlobalFlags .) .HasAvailableInheritedFlags}}
|
||||
|
||||
Global Flags:
|
||||
{{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasHelpSubCommands}}
|
||||
{{(backendFlags . false).FlagUsages | trimTrailingWhitespaces}}
|
||||
|
||||
Backend Flags:
|
||||
{{(backendFlags . true).FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasHelpSubCommands}}
|
||||
|
||||
Additional help topics:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}}
|
||||
{{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}
|
||||
|
Loading…
Reference in New Issue
Block a user