authorize: add support for custom templates

This adds support for providing custom Go templates for use in the
`rclone authorize` command.

Fixes #6741
This commit is contained in:
Hunter Wittenborn 2023-02-24 09:08:38 -06:00 committed by GitHub
parent 745c0af571
commit 56b582cdb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 54 additions and 10 deletions

View file

@ -12,12 +12,14 @@ import (
var (
noAutoBrowser bool
template string
)
func init() {
cmd.Root.AddCommand(commandDefinition)
cmdFlags := commandDefinition.Flags()
flags.BoolVarP(cmdFlags, &noAutoBrowser, "auth-no-open-browser", "", false, "Do not automatically open auth link in default browser")
flags.StringVarP(cmdFlags, &template, "template", "", "", "The path to a custom Go template for generating HTML responses")
}
var commandDefinition = &cobra.Command{
@ -28,13 +30,15 @@ Remote authorization. Used to authorize a remote or headless
rclone from a machine with a browser - use as instructed by
rclone config.
Use the --auth-no-open-browser to prevent rclone to open auth
link in default browser automatically.`,
Use --auth-no-open-browser to prevent rclone to open auth
link in default browser automatically.
Use --template to generate HTML output via a custom Go template. If a blank string is provided as an argument to this flag, the default template is used.`,
Annotations: map[string]string{
"versionIntroduced": "v1.27",
},
RunE: func(command *cobra.Command, args []string) error {
cmd.CheckArgs(1, 3, command, args)
return config.Authorize(context.Background(), args, noAutoBrowser)
return config.Authorize(context.Background(), args, noAutoBrowser, template)
},
}