|
1 | | -package bisync |
| 1 | +//go:build none |
| 2 | + |
| 3 | +// Create the help text for the rc |
| 4 | +// |
| 5 | +// Run with go generate ./cmd/bisync (defined in rc.go) |
| 6 | +package main |
2 | 7 |
|
3 | 8 | import ( |
4 | | - "strconv" |
| 9 | + "fmt" |
| 10 | + "os" |
5 | 11 | "strings" |
| 12 | + |
| 13 | + "github.com/muesli/reflow/wordwrap" |
| 14 | + "github.com/rclone/rclone/cmd" |
| 15 | + "github.com/rclone/rclone/cmd/bisync" |
| 16 | + "github.com/rclone/rclone/fs" |
| 17 | + "github.com/spf13/pflag" |
| 18 | + "golang.org/x/text/cases" |
| 19 | + "golang.org/x/text/language" |
6 | 20 | ) |
7 | 21 |
|
8 | | -func makeHelp(help string) string { |
9 | | - replacer := strings.NewReplacer( |
10 | | - "|", "`", |
11 | | - "{MAXDELETE}", strconv.Itoa(DefaultMaxDelete), |
12 | | - "{CHECKFILE}", DefaultCheckFilename, |
13 | | - // "{WORKDIR}", DefaultWorkdir, |
14 | | - ) |
15 | | - return replacer.Replace(help) |
| 22 | +// Output the help to stdout |
| 23 | +func main() { |
| 24 | + out := os.Stdout |
| 25 | + if len(os.Args) > 1 { |
| 26 | + var err error |
| 27 | + out, err = os.Create(os.Args[1]) |
| 28 | + if err != nil { |
| 29 | + fs.Fatalf(nil, "Open output failed: %v", err) |
| 30 | + } |
| 31 | + defer out.Close() |
| 32 | + } |
| 33 | + fmt.Fprintf(out, "<!--- Docs generated by help.go - use go generate to rebuild - DO NOT EDIT --->\n\n") |
| 34 | + fmt.Fprint(out, RcHelp()) |
16 | 35 | } |
17 | 36 |
|
18 | | -var shortHelp = `Perform bidirectional synchronization between two paths.` |
19 | | - |
20 | | -var rcHelp = makeHelp(`This takes the following parameters |
21 | | -
|
22 | | -- path1 - a remote directory string e.g. |drive:path1| |
23 | | -- path2 - a remote directory string e.g. |drive:path2| |
24 | | -- dryRun - dry-run mode |
25 | | -- resync - performs the resync run |
26 | | -- checkAccess - abort if {CHECKFILE} files are not found on both filesystems |
27 | | -- checkFilename - file name for checkAccess (default: {CHECKFILE}) |
28 | | -- maxDelete - abort sync if percentage of deleted files is above |
29 | | - this threshold (default: {MAXDELETE}) |
30 | | -- force - Bypass maxDelete safety check and run the sync |
31 | | -- checkSync - |true| by default, |false| disables comparison of final listings, |
32 | | - |only| will skip sync, only compare listings from the last run |
33 | | -- createEmptySrcDirs - Sync creation and deletion of empty directories. |
34 | | - (Not compatible with --remove-empty-dirs) |
35 | | -- removeEmptyDirs - remove empty directories at the final cleanup step |
36 | | -- filtersFile - read filtering patterns from a file |
37 | | -- ignoreListingChecksum - Do not use checksums for listings |
38 | | -- resilient - Allow future runs to retry after certain less-serious errors, instead of requiring resync. |
39 | | -- workdir - server directory for history files (default: |~/.cache/rclone/bisync|) |
40 | | -- backupdir1 - --backup-dir for Path1. Must be a non-overlapping path on the same remote. |
41 | | -- backupdir2 - --backup-dir for Path2. Must be a non-overlapping path on the same remote. |
42 | | -- noCleanup - retain working files |
| 37 | +// RcHelp returns the rc help |
| 38 | +func RcHelp() string { |
| 39 | + return wordwrap.String(bisync.MakeHelp(`This takes the following parameters: |
43 | 40 |
|
| 41 | +- path1 (required) - (string) a remote directory string e.g. ||drive:path1|| |
| 42 | +- path2 (required) - (string) a remote directory string e.g. ||drive:path2|| |
| 43 | +- dryRun - (bool) dry-run mode |
| 44 | +`+GenerateParams()+` |
44 | 45 | See [bisync command help](https://rclone.org/commands/rclone_bisync/) |
45 | 46 | and [full bisync description](https://rclone.org/bisync/) |
46 | | -for more information.`) |
47 | | - |
48 | | -var longHelp = shortHelp + makeHelp(` |
49 | | -
|
50 | | -[Bisync](https://rclone.org/bisync/) provides a |
51 | | -bidirectional cloud sync solution in rclone. |
52 | | -It retains the Path1 and Path2 filesystem listings from the prior run. |
53 | | -On each successive run it will: |
54 | | -
|
55 | | -- list files on Path1 and Path2, and check for changes on each side. |
56 | | - Changes include |New|, |Newer|, |Older|, and |Deleted| files. |
57 | | -- Propagate changes on Path1 to Path2, and vice-versa. |
| 47 | +for more information. |
| 48 | +`), 76) |
| 49 | +} |
58 | 50 |
|
59 | | -Bisync is considered an **advanced command**, so use with care. |
60 | | -Make sure you have read and understood the entire [manual](https://rclone.org/bisync) |
61 | | -(especially the [Limitations](https://rclone.org/bisync/#limitations) section) |
62 | | -before using, or data loss can result. Questions can be asked in the |
63 | | -[Rclone Forum](https://forum.rclone.org/). |
| 51 | +// example: "create-empty-src-dirs" -> "createEmptySrcDirs" |
| 52 | +func toCamel(s string) string { |
| 53 | + split := strings.Split(s, "-") |
| 54 | + builder := strings.Builder{} |
| 55 | + for i, word := range split { |
| 56 | + if i == 0 { // first word always all lowercase |
| 57 | + builder.WriteString(strings.ToLower(word)) |
| 58 | + continue |
| 59 | + } |
| 60 | + builder.WriteString(cases.Title(language.AmericanEnglish).String(word)) |
| 61 | + } |
| 62 | + return builder.String() |
| 63 | +} |
64 | 64 |
|
65 | | -See [full bisync description](https://rclone.org/bisync/) for details.`) |
| 65 | +// GenerateParams automatically generates the param list from commandDefinition.Flags |
| 66 | +func GenerateParams() string { |
| 67 | + builder := strings.Builder{} |
| 68 | + fn := func(flag *pflag.Flag) { |
| 69 | + if flag.Hidden { |
| 70 | + return |
| 71 | + } |
| 72 | + builder.WriteString(fmt.Sprintf("- %s - (%s) %s \n", toCamel(flag.Name), flag.Value.Type(), flag.Usage)) |
| 73 | + } |
| 74 | + commandDefinition, _, _ := cmd.Root.Find([]string{"bisync"}) |
| 75 | + commandDefinition.Flags().VisitAll(fn) |
| 76 | + return builder.String() |
| 77 | +} |
0 commit comments