mirror of
https://github.com/rclone/rclone.git
synced 2026-10-28 14:28:38 -04:00
Before this change, `--max-delete` and `--dry-run` were read from the
global config by `applyContext`, which only the command line called. The
rc `sync/bisync` call started from empty `Options` and never ran it, so it
ignored both settings:
- A dry run requested through the global option (`_config`
`{"DryRun": true}` or the flat `dry_run` parameter) was ignored.
`setDryRun` resets `ci.DryRun` from `opt.DryRun` before copying, and
`opt.DryRun` was only set by bisync's own `dryRun` parameter.
- When the `maxDelete` parameter was omitted, the `--max-delete` limit was
0%. A `max_delete` set through `_config` or the flat parameter was not
used for that limit, and applied to the inner syncs as a file count
instead.
After this change, `Bisync` runs `applyContext` itself, on its own copy of
the config, so the command line, the rc, and any other caller follow the
same rules, and `Options.MaxDelete` and `Options.DryRun` are set by
`Bisync`. With no `--max-delete` anywhere, the limit is 50%, as #5680 says
the rc should.
The rc's `maxDelete` and `dryRun` parameters now set the call's config.
`maxDelete` overrides the global `--max-delete`. `dryRun: true` asks for a
dry run, but `dryRun: false` doesn't cancel one from the global config, so
the run is a dry run if either asks for one. The `maxDelete` parameter is
also documented again; it was left out when the rc help became generated
from the command's flags.
79 lines
2.2 KiB
Go
79 lines
2.2 KiB
Go
//go:build none
|
|
|
|
// Create the help text for the rc
|
|
//
|
|
// Run with go generate ./cmd/bisync (defined in rc.go)
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/muesli/reflow/wordwrap"
|
|
"github.com/rclone/rclone/cmd"
|
|
"github.com/rclone/rclone/cmd/bisync"
|
|
"github.com/rclone/rclone/fs"
|
|
"github.com/spf13/pflag"
|
|
"golang.org/x/text/cases"
|
|
"golang.org/x/text/language"
|
|
)
|
|
|
|
// Output the help to stdout
|
|
func main() {
|
|
out := os.Stdout
|
|
if len(os.Args) > 1 {
|
|
var err error
|
|
out, err = os.Create(os.Args[1])
|
|
if err != nil {
|
|
fs.Fatalf(nil, "Open output failed: %v", err)
|
|
}
|
|
defer out.Close()
|
|
}
|
|
fmt.Fprintf(out, "<!--- Docs generated by help.go - use go generate to rebuild - DO NOT EDIT --->\n\n")
|
|
fmt.Fprint(out, RcHelp())
|
|
}
|
|
|
|
// RcHelp returns the rc help
|
|
func RcHelp() string {
|
|
return wordwrap.String(bisync.MakeHelp(`This takes the following parameters:
|
|
|
|
- path1 (required) - (string) a remote directory string e.g. ||drive:path1||
|
|
- path2 (required) - (string) a remote directory string e.g. ||drive:path2||
|
|
- dryRun - (bool) dry-run mode
|
|
- maxDelete - (int) Safety check on maximum percentage of deleted files allowed. If exceeded, the bisync run will abort. (default: {MAXDELETE}%)
|
|
`+GenerateParams()+`
|
|
See [bisync command help](https://rclone.org/commands/rclone_bisync/)
|
|
and [full bisync description](https://rclone.org/bisync/)
|
|
for more information.
|
|
`), 76)
|
|
}
|
|
|
|
// example: "create-empty-src-dirs" -> "createEmptySrcDirs"
|
|
func toCamel(s string) string {
|
|
split := strings.Split(s, "-")
|
|
builder := strings.Builder{}
|
|
for i, word := range split {
|
|
if i == 0 { // first word always all lowercase
|
|
builder.WriteString(strings.ToLower(word))
|
|
continue
|
|
}
|
|
builder.WriteString(cases.Title(language.AmericanEnglish).String(word))
|
|
}
|
|
return builder.String()
|
|
}
|
|
|
|
// GenerateParams automatically generates the param list from commandDefinition.Flags
|
|
func GenerateParams() string {
|
|
builder := strings.Builder{}
|
|
fn := func(flag *pflag.Flag) {
|
|
if flag.Hidden {
|
|
return
|
|
}
|
|
builder.WriteString(fmt.Sprintf("- %s - (%s) %s \n", toCamel(flag.Name), flag.Value.Type(), flag.Usage))
|
|
}
|
|
commandDefinition, _, _ := cmd.Root.Find([]string{"bisync"})
|
|
commandDefinition.Flags().VisitAll(fn)
|
|
return builder.String()
|
|
}
|