Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix device config storage with ints #575

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions cmd/jag/commands/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,25 @@ func stringOr(data map[string]interface{}, key string, def string) string {
}

func intOr(data map[string]interface{}, key string, def int) int {
if val, ok := data[key].(float64); ok {
return int(val)
// Attempt to retrieve the value using the original key.
val, ok := data[key]
if !ok {
// If not found, try the lowercase version of the key.
val, ok = data[strings.ToLower(key)]
if !ok {
return def
}
}
// Viper converts all keys to lowercase, so we need to check for that as well.
key = strings.ToLower(key)
if val, ok := data[key].(float64); ok {
return int(val)

// Check if the value is an int or float64, and convert as needed.
switch v := val.(type) {
case int:
return v
case float64:
return int(v)
default:
return def
}
return def
}

func GetDevice(ctx context.Context, sdk *SDK, checkPing bool, deviceSelect deviceSelect) (Device, error) {
Expand Down