1
0
Fork 0
mirror of https://codeberg.org/june64/mrvc.git synced 2026-01-10 16:06:33 +01:00

introduce configuration options for recursively getting rooms

Introduce option for configuring maximum depth and option for only
including suggested rooms.
This commit is contained in:
June 2025-08-19 02:53:07 +02:00
commit 6309b94498
Signed by: june
SSH key fingerprint: SHA256:o9EAq4Y9N9K0pBQeBTqhSDrND5E7oB+60ZNx0U1yPe0
3 changed files with 38 additions and 12 deletions

View file

@ -24,6 +24,8 @@ type configOptions struct {
token configOption[string]
rooms configOption[rooms]
recursive configOption[bool]
recursionMaxDepth configOption[int]
recursionSuggestedOnly configOption[bool]
printHomeserverMemberCount configOption[bool]
homeserverVersionInfoTimeout configOption[time.Duration]
}
@ -33,6 +35,8 @@ type Config struct {
Token string
Rooms rooms
Recursive bool
RecursionMaxDepth *int
RecursionSuggestedOnly bool
PrintHomeserverMemberCount bool
HomeserverVersionInfoTimeout time.Duration
}
@ -42,6 +46,8 @@ var configOpts = configOptions{
token: configOption[string]{"token", "", "The Matrix access token to use.", "MRVC_TOKEN"},
rooms: configOption[rooms]{"room", []string{}, "The Matrix room to check. The flag can be set multiple times to check multiple rooms.", "MRVC_ROOM"},
recursive: configOption[bool]{"recursive", false, "Recursively check the child rooms for the given rooms (spaces) as well.", "MRVC_RECURSIVE"},
recursionMaxDepth: configOption[int]{"recursion-max-depth", 0, "The maximum depth when recursively getting child rooms. Defaults to 0, which gets interpreted as the servers default.", "MRVC_RECURSION_MAX_DEPTH"},
recursionSuggestedOnly: configOption[bool]{"recursion-suggested-only", false, "Only include the suggested children, when recursively getting child rooms.", "MRVC_RECURSION_SUGGESTED_ONLY"},
printHomeserverMemberCount: configOption[bool]{"print-homeserver-member-count", false, "Print the member count for each homeserver.", "MRVC_PRINT_HOMESERVER_MEMBER_COUNT"},
homeserverVersionInfoTimeout: configOption[time.Duration]{"homeserver-version-info-timeout", time.Second * 5, "Timeout for getting the homeservers version information per homeserver.", "MRVC_HOMESERVER_VERSION_INFO_TIMEOUT"},
}
@ -89,6 +95,8 @@ func (configOpt configOption[T]) getConfigValueWithError(configFlag *T, visitedF
var userIdFlag = flag.String(configOpts.userID.getFlagArgs())
var tokenFlag = flag.String(configOpts.token.getFlagArgs())
var recursiveFlag = flag.Bool(configOpts.recursive.getFlagArgs())
var recursionMaxDepthFlag = flag.Int(configOpts.recursionMaxDepth.getFlagArgs())
var recursionSuggestedOnlyFlag = flag.Bool(configOpts.recursionSuggestedOnly.getFlagArgs())
var printHomeserverMemberCountFlag = flag.Bool(configOpts.printHomeserverMemberCount.getFlagArgs())
var homeserverVersionInfoTimeoutFlag = flag.Duration(configOpts.homeserverVersionInfoTimeout.getFlagArgs())
@ -130,6 +138,28 @@ func Get() Config {
}
return parsedEnvVar
})
givenRecursionMaxDepth := configOpts.recursionMaxDepth.getConfigValueWithDefault(recursionMaxDepthFlag, visitedFlags, func(envVar string) int {
parsedEnvVar, err := strconv.Atoi(envVar)
if err != nil {
log.Printf("Error parsing %s:\n", configOpts.recursionMaxDepth.envVarName)
log.Fatal(err)
}
return parsedEnvVar
})
// Since we actually want an *int, interpret 0 as nil as described in the help text.
if givenRecursionMaxDepth != 0 {
config.RecursionMaxDepth = &givenRecursionMaxDepth
} else {
config.RecursionMaxDepth = nil
}
config.RecursionSuggestedOnly = configOpts.recursionSuggestedOnly.getConfigValueWithDefault(recursionSuggestedOnlyFlag, visitedFlags, func(envVar string) bool {
parsedEnvVar, err := strconv.ParseBool(envVar)
if err != nil {
log.Printf("Error parsing %s:\n", configOpts.recursionSuggestedOnly.envVarName)
log.Fatal(err)
}
return parsedEnvVar
})
config.PrintHomeserverMemberCount = configOpts.printHomeserverMemberCount.getConfigValueWithDefault(printHomeserverMemberCountFlag, visitedFlags, func(envVar string) bool {
parsedEnvVar, err := strconv.ParseBool(envVar)
if err != nil {