Repository: rclone/rclone
File: fs/config/rc.go (Go)

Code before:
		return nil, err
	}
	return DumpRcRemote(name), nil
}

func init() {
	rc.Add(rc.Call{
		Path:         "config/listremotes",
		Fn:           rcListRemotes,
		Title:        "Lists the remotes in the config file and defined in environment variables.",
		AuthRequired: true,
		Help: `
Returns
- remotes - array of remote names

See the [listremotes](/commands/rclone_listremotes/) command for more information on the above.
`,
	})
}

var rcMatchEnv = regexp.MustCompile(`^RCLONE_CONFIG_(.*?)_TYPE=.*$`)

// Return the a list of remotes in the config file
// including any defined by environment variables.
func rcListRemotes(ctx context.Context, in rc.Params) (out rc.Params, err error) {
	remotes := LoadedData().GetSectionList()
	for _, item := range os.Environ() {
		matches := rcMatchEnv.FindStringSubmatch(item)
		if len(matches) == 2 {
			remotes = append(remotes, strings.ToLower(matches[1]))
		}
	}
	out = rc.Params{
		"remotes": remotes,
	}
	return out, nil
}

func init() {
	rc.Add(rc.Call{
		Path:         "config/providers",
		Fn:           rcProviders,
		Title:        "Shows how providers are configured in the config file.",
		AuthRequired: true,
		Help: `
Returns a JSON object:
- providers - array of objects

See the [config providers](/commands/rclone_config_providers/) command for more information on the above.
`,
	})

Review comment (suggestion):
I was looking to at your other PR #7058 and I realised we already have a function to do this which is called by `rclone listremotes`

https://github.com/rclone/rclone/blob/998d1d1727e5a76b0af2b61bc29a2bd8fa882b9a/cmd/listremotes/listremotes.go#L38

https://github.com/rclone/rclone/blob/998d1d1727e5a76b0af2b61bc29a2bd8fa882b9a/fs/config/config.go#L642-L644

So what I think we should do is call that function here and lose the looking in the environment because that function does it already.

Hopefully your tests won't need any changes

Code after:
}

func init() {
	rc.Add(rc.Call{
		Path:         "config/listremotes",
		Fn:           rcListRemotes,
		Title:        "Lists the remotes in the config file and defined in environment variables.",
		AuthRequired: true,
		Help: `
Returns
- remotes - array of remote names

See the [listremotes](/commands/rclone_listremotes/) command for more information on the above.
`,
	})
}

// Return the a list of remotes in the config file
// including any defined by environment variables.
func rcListRemotes(ctx context.Context, in rc.Params) (out rc.Params, err error) {
	remotes := FileSections()
	out = rc.Params{
		"remotes": remotes,
	}
	return out, nil
}

func init() {
	rc.Add(rc.Call{
		Path:         "config/providers",
		Fn:           rcProviders,
		Title:        "Shows how providers are configured in the config file.",
		AuthRequired: true,
		Help: `
Returns a JSON object:
- providers - array of objects

See the [config providers](/commands/rclone_config_providers/) command for more information on the above.
`,
	})
}

// Return the config file providers
func rcProviders(ctx context.Context, in rc.Params) (out rc.Params, err error) {
	out = rc.Params{
		"providers": fs.Registry,
	}
	return out, nil
}

func init() {