forked from rclone/rclone
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,530 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,4 @@ __pycache__ | |
/docs/static/img/logos/ | ||
resource_windows_*.syso | ||
.devcontainer | ||
.vscode/launch.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Package setprofile provides the setprofile command. | ||
package setprofile | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"os" | ||
|
||
"github.com/rclone/rclone/cmd" | ||
"github.com/rclone/rclone/fs" | ||
profiles "github.com/rclone/rclone/fs/config/configprofiles" | ||
"github.com/rclone/rclone/fs/config/flags" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
FlagsFrom fs.CommaSepList // FlagsFrom imports command-specific flags from these subcommands (note: will error if commands have conflicting flags.) | ||
) | ||
|
||
func init() { | ||
cmd.Root.AddCommand(commandDefinition) | ||
cmdFlags := commandDefinition.Flags() | ||
flags.FVarP(cmdFlags, &FlagsFrom, "flags-from", "", "If set, import command-specific flags from these subcommands (note: will error if commands have conflicting flags.)", "") | ||
|
||
commandDefinition.PersistentPreRunE = addFlagsFrom | ||
commandDefinition.FParseErrWhitelist.UnknownFlags = true // allow unknown flags until we do our custom parsing | ||
} | ||
|
||
func addFlagsFrom(setprofilecmd *cobra.Command, args []string) error { | ||
// prevent verbose getting double-counted (it's a CountVarP) | ||
verbose := setprofilecmd.Flags().Lookup("verbose").Value.String() | ||
defer func() { | ||
err := setprofilecmd.Flags().Lookup("verbose").Value.Set(verbose) | ||
if err != nil { | ||
fs.Errorf(nil, "error trying to set verbose to %s: %v", verbose, err) | ||
} | ||
}() | ||
|
||
if len(FlagsFrom) > 0 { | ||
for _, subcommand := range FlagsFrom { | ||
sc, _, err := cmd.Root.Find([]string{subcommand}) | ||
if err != nil { | ||
return err | ||
} | ||
setprofilecmd.Flags().AddFlagSet(sc.Flags()) | ||
} | ||
} | ||
// now reenable validation and reparse the flags | ||
commandDefinition.FParseErrWhitelist.UnknownFlags = false | ||
return setprofilecmd.ParseFlags(os.Args) | ||
} | ||
|
||
var commandDefinition = &cobra.Command{ | ||
Use: "setprofile [args...] [flags...] --save-profile PROFILENAME", | ||
Short: `Save a profile with the args and flags passed in.`, | ||
Long: ` | ||
This command does nothing except set a profile. | ||
For more detailed profile config options, see: | ||
rclone config profile | ||
`, | ||
Annotations: map[string]string{ | ||
"groups": "Config", | ||
}, | ||
Run: func(command *cobra.Command, args []string) { | ||
cmd.CheckArgs(0, 100, command, args) | ||
cmd.Run(false, false, command, func() error { | ||
ctx, ci := fs.AddConfig(context.Background()) | ||
if ci.SaveProfile == "" { | ||
return errors.New("must use --save-profile PROFILENAME with this command") | ||
} | ||
return profiles.HandleProfiles(ctx, command, args) | ||
}) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.