Skip to content

Commit

Permalink
incus-doc: Don't try to guess types
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <[email protected]>
  • Loading branch information
stgraber committed Dec 23, 2023
1 parent ad6fd0e commit fc5689a
Showing 1 changed file with 1 addition and 33 deletions.
34 changes: 1 addition & 33 deletions internal/server/config/generate/incus_doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
"time"

Expand All @@ -37,37 +36,6 @@ type doc struct {
Configs map[string]any `json:"configs"`
}

// detectType detects the type of a string and returns the corresponding value.
func detectType(s string) any {
i, err := strconv.Atoi(s)
if err == nil {
return i
}

b, err := strconv.ParseBool(s)
if err == nil {
return b
}

f, err := strconv.ParseFloat(s, 64)
if err == nil {
return f
}

t, err := time.Parse(time.RFC3339, s)
if err == nil {
return t
}

// special characters handling
if s == "-" {
return ""
}

// If all conversions fail, it's a string
return s
}

// sortConfigKeys alphabetically sorts the entries by key (config option key) within each config group in an entity.
func sortConfigKeys(projectEntries map[string]any) {
for _, entityValue := range projectEntries {
Expand Down Expand Up @@ -210,7 +178,7 @@ func parse(path string, outputJSONPath string, excludedPaths []string) (*doc, er
continue
}

configKeyEntry[metadataMap["key"]].(map[string]any)[dataKVMatch[1]] = detectType(dataKVMatch[2])
configKeyEntry[metadataMap["key"]].(map[string]any)[dataKVMatch[1]] = dataKVMatch[2]
}

_, ok = groupKeyEntry[metadataMap["group"]]
Expand Down

0 comments on commit fc5689a

Please sign in to comment.