I am looking to use some of the RClone components in another Golang programme. I have imported the components I need and all seems to be working fine. To avoid potential breaking changes in the future though, I thought it may be best to pass the Args to RClone's cmd.Main so that it is as close to the equivalent of calling RClone as an executable.
fmt.Println("Creating encrypted configuration...")
// Create the local storage mount
os.Args = []string{os.Args[0]}
os.Args = append(os.Args,
"config",
"create",
"storage",
"local",
"--config",
"rclone.conf")
cmd.Main()
// Create the encrypted storage mount
randomPassword, err := encode.GenerateRandomString(32)
if err != nil {
return err
}
os.Args = []string{os.Args[0]}
os.Args = append(os.Args,
"config",
"create",
"encrypted_storage",
"crypt",
"remote=storage",
"password="+randomPassword,
"--non-interactive",
"--obscure",
"--config",
"rclone.conf")
cmd.Main()
The issue is that calling cmd.Main() twice creates a conflict where the flags are trying to be defined twice, all sourced from the pflag package:
panic: ./rclone-app flag redefined: verbose
I think I understand the issue, it is trying to redeclare flags it already declared on the first run (rclone/configflags.go at 1107da7247db32199fde92f42c916bcb4c60dc3f · rclone/rclone · GitHub). Has anyone found a better workflow for this?
In addition to the above two commands I will eventually look to implement a mount of encrypted_storage
too, so will need a way to pass in to the mount
command as well as the config
.